@@ -0,0 +1,43 @@ | |||||
import sys | |||||
def rotate(x, y): | |||||
return (x + y) % 26 | |||||
def shift(letter, n): | |||||
x = ord(letter) - ord("A") | |||||
y = rotate(x, n) | |||||
return chr(ord("A") + y) | |||||
def rot13(message): | |||||
message = "".join([x for x in message if x.isalpha()]) | |||||
message = message.upper() | |||||
res = "" | |||||
for c in message: | |||||
res += shift(c, 13) | |||||
return res | |||||
def encrypt(key, message): | |||||
message = "".join([x for x in message if x.isalpha()]) | |||||
message = message.upper() | |||||
res = "" | |||||
i = 0 | |||||
for c in message: | |||||
x = ord(key[i % len(key)]) - ord("A") | |||||
res += shift(c, x) | |||||
i += 1 | |||||
return res | |||||
def main(): | |||||
cle = sys.argv[1] | |||||
message = sys.argv[2] | |||||
res = encrypt(cle, message) | |||||
print(res) | |||||
if __name__ == "__main__": | |||||
main() |
@@ -0,0 +1,33 @@ | |||||
def rotate(x, y): | |||||
return (x + y) % 26 | |||||
def shift(letter, n): | |||||
x = ord(letter) - ord('A') | |||||
y = rotate(x, n) | |||||
return chr(ord('A') + y) | |||||
def rot13(message): | |||||
message = "".join([x for x in message if x.isalpha()]) | |||||
message = message.upper() | |||||
res = "" | |||||
for c in message: | |||||
res += shift(c, 13) | |||||
return res | |||||
def test_rotate(): | |||||
assert rotate(1, 3) == 4 | |||||
assert rotate(25, 3) == 2 | |||||
def test_shift(): | |||||
assert shift('A', 2) == 'C' | |||||
assert shift('E', 2) == 'G' | |||||
assert shift('Y', 3) == 'B' | |||||
def test_rot13(): | |||||
assert rot13('hello') == 'URYYB' | |||||
assert rot13('URYYB') == 'HELLO' |
@@ -0,0 +1,6 @@ | |||||
Message-1 was encrypted with the key 'M'. Decrypt it | |||||
Message-2 was encrypted with an unknown, 3 letters key. Decrypt it too, | |||||
knowing that it contains the string 'Plekszy-Gladz' | |||||
spoiler: xdr |
@@ -0,0 +1,62 @@ | |||||
import sys | |||||
import string | |||||
def rotate(x, y): | |||||
return (x - y) % 26 | |||||
def shift(letter, n): | |||||
x = ord(letter) - ord("A") | |||||
y = rotate(x, n) | |||||
return chr(ord("A") + y) | |||||
def rot13(message): | |||||
message = "".join([x for x in message if x.isalpha()]) | |||||
message = message.upper() | |||||
res = "" | |||||
for c in message: | |||||
res += shift(c, 13) | |||||
return res | |||||
def decrypt(key, message): | |||||
message = "".join([x for x in message if x.isalpha()]) | |||||
message = message.upper() | |||||
res = "" | |||||
i = 0 | |||||
for c in message: | |||||
x = ord(key[i % len(key)]) - ord("A") | |||||
res += shift(c, x) | |||||
i += 1 | |||||
return res | |||||
def try_with_key(key, message): | |||||
res = decrypt(key, message) | |||||
if "PLEKSZYGLADZ" in res: | |||||
return res | |||||
def main(): | |||||
message = sys.argv[1] | |||||
print(decrypt('N', message)) | |||||
""" | |||||
message = sys.argv[1] | |||||
letters = string.ascii_uppercase | |||||
for a in letters: | |||||
for b in letters: | |||||
for c in letters: | |||||
key = a + b + c | |||||
res = try_with_key(key, message) | |||||
if res: | |||||
print(res) | |||||
print("key:", key) | |||||
return | |||||
""" | |||||
if __name__ == "__main__": | |||||
main() |
@@ -0,0 +1 @@ | |||||
GVAGVAFRFGRZCNERQHFCRPGERCERARMYRFZRFHERFARPRFFNVERF |
@@ -0,0 +1 @@ | |||||
IHDXUVZKRISCBNJWBXIDUWVVODUBPRFQRIRGBUR |