Skip to content

Instantly share code, notes, and snippets.

@faidamine
Created April 25, 2017 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faidamine/95b1f678533982b14babda2da42fac21 to your computer and use it in GitHub Desktop.
Save faidamine/95b1f678533982b14babda2da42fac21 to your computer and use it in GitHub Desktop.
#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