Created
November 25, 2019 13:51
-
-
Save lemenkov/f0e3a9fa30c34973407a48050a04738d to your computer and use it in GitHub Desktop.
Test for topoh module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
word64digits = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+." | |
topo_hiding_prefix = b"DLGCH_" | |
def word64encode(Str): | |
Out = b"" | |
i = len(Str) | |
j = 0 | |
while i >= 3: | |
Out += bytes([word64digits[Str[j+0] >> 2]]); | |
Out += bytes([word64digits[((Str[j+0] << 4) & 0x30) | (Str[j+1] >> 4)]]) | |
Out += bytes([word64digits[((Str[j+1] << 2) & 0x3c) | (Str[j+2] >> 6)]]) | |
Out += bytes([word64digits[Str[j+2] & 0x3f]]) | |
i -= 3 | |
j += 3 | |
if i > 0: | |
Out += bytes([word64digits[Str[j+0] >> 2]]) | |
Fragment = (Str[j+0] << 4) & 0x30 | |
if i > 1: | |
Fragment |= Str[j+1] >> 4; | |
Out += bytes([word64digits[Fragment]]) | |
if i < 2: | |
Out += b'-' | |
else: | |
Out += bytes([word64digits[(Str[1] << 2) & 0x3c]]) | |
Out += b'-' | |
return Out | |
def str_xor(Str0, Str1): | |
Out = b"" | |
for i in range(len(Str0)): | |
Out += bytes([Str0[i] ^ Str1[i % len(Str1)]]) | |
return Out | |
class TestEncryptMethod(unittest.TestCase): | |
def test_encrypt(self): | |
Msg = b"my message I want to encrypt" | |
Seed = b"OpenSIPS" | |
Wanted = b'DLGCH_IglFAzY6IzIoFUUncz4xPTtQEQFzLD4wPQkVGg--' | |
self.assertEqual(Wanted, topo_hiding_prefix + word64encode(str_xor(Msg, Seed))) | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment