Last active
July 23, 2022 16:14
-
-
Save cy4n/41a0be7b6826899f9f1287b5326d5b30 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/python | |
import sys, binascii, base64, string, random | |
flag = sys.argv[1] | |
print(flag) | |
def toHex(m): | |
return binascii.hexlify(m) | |
def toBase64(m): | |
return base64.b64encode(m) | |
def fromBase64(m): | |
return base64.b64decode(m) | |
def rot13(m): | |
t = string.maketrans( | |
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz:", | |
"NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm#") | |
return string.translate(m,t) | |
def fromRot13(m): | |
t = string.maketrans( | |
"NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm#", | |
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz:") | |
return string.translate(m,t) | |
def xOR0x42(m): | |
return toHex(''.join(chr(ord(c) ^ 0x42) for c in m)) | |
def fromXOR0x42(m): | |
return toHex(''.join(chr(c ^ 0x42) for c in binascii.unhexlify(m))) | |
def encrypt(s): | |
functions = [xOR0x42, toBase64, rot13] | |
# for i in range(random.randint(8,14)): # egal wie oft:D | |
a = random.randint(1,len(s)/2) | |
b = random.randint(a+1,len(s)-1) | |
tmp = [s[0:a],s[a:b],s[b:]] # mach 3 strings in einer liste | |
for j in range(3): | |
random0bis2 = random.randint(0,2) | |
tmp[j] = str(random0bis2) + functions[random0bis2](tmp[j]) | |
out = ':'.join(tmp) # string1:string2:string3 (jeweils random mit einer function vercryptet) | |
return out | |
def decrypt(s): | |
fromFunctions = [fromXOR0x42, fromBase64, fromRot13] | |
out='' | |
strings = s.split(':') | |
for j in range(3): | |
currentString = string[j] | |
currentDecoded=fromFunctions[currentString[0]](currentString[1:]) | |
out = out + currentDecoded | |
return(out) | |
if __name__ == "__main__": | |
print(decrypt(flag)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment