Created
April 25, 2017 23:37
-
-
Save faidamine/95b1f678533982b14babda2da42fac21 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 | |
#Faid Mohammed Amine | |
#Fb : piratuer | |
#Pad 200 pts ( YUBITSEC CTF 2017 ) | |
f = open("encrypted_2","w") | |
secret = "***REDACTED***" | |
key = "JdKeVFaSdfCxZ3471ZxCVbN" | |
startchar = ' ' # 32 | |
endchar = '~' # 126 | |
modular = ord(endchar) - ord(startchar) + 1 | |
def encrypt(message, key): | |
ret = "" | |
for i in range(len(message)): | |
messagechar = ord(message[i]) - ord(startchar) | |
keychar = ord(key[i]) - ord(startchar) | |
calculatedchar = (messagechar + keychar) % modular | |
convertedchar = chr(calculatedchar + ord(startchar)) | |
ret += convertedchar | |
return ret | |
#f.write(encrypt(secret,key)) | |
#output : " $:m/+y'v@N3bIzs,yMh9>K,",key " | |
def decrypt(ciphertext, key): | |
retn = [] | |
for i in range(len(ciphertext)): | |
messagechar = ord(ciphertext[i]) - ord(startchar) | |
keychar = ord(key[i]) - ord(startchar) | |
calculatedchar = (messagechar - keychar) % modular | |
convertedchar = chr(calculatedchar + ord(startchar)) | |
retn.append(convertedchar) | |
return "".join(retn) | |
ciphertxt = open('encrypted_2').read() | |
print decrypt(ciphertxt,key) | |
#print decrypt("$:m/+y'v@N3bIzs,yMh9>K,",key) | |
#Thanks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment