Ver a proveniência

Prepare workshop

master
Dimitri Merejkowsky há 5 anos
ascendente
cometimento
93d1a98f60
6 ficheiros alterados com 146 adições e 0 eliminações
  1. +43
    -0
      saison-2/sources/espionnage/bordurie/encrypt.py
  2. +33
    -0
      saison-2/sources/espionnage/bordurie/test_chiffre.py
  3. +6
    -0
      saison-2/sources/espionnage/notes
  4. +62
    -0
      saison-2/sources/espionnage/syldavie/decrypt.py
  5. +1
    -0
      saison-2/sources/espionnage/syldavie/message-1.txt
  6. +1
    -0
      saison-2/sources/espionnage/syldavie/message-2.txt

+ 43
- 0
saison-2/sources/espionnage/bordurie/encrypt.py Ver ficheiro

@@ -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()

+ 33
- 0
saison-2/sources/espionnage/bordurie/test_chiffre.py Ver ficheiro

@@ -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'

+ 6
- 0
saison-2/sources/espionnage/notes Ver ficheiro

@@ -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

+ 62
- 0
saison-2/sources/espionnage/syldavie/decrypt.py Ver ficheiro

@@ -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()

+ 1
- 0
saison-2/sources/espionnage/syldavie/message-1.txt Ver ficheiro

@@ -0,0 +1 @@
GVAGVAFRFGRZCNERQHFCRPGERCERARMYRFZRFHERFARPRFFNVERF

+ 1
- 0
saison-2/sources/espionnage/syldavie/message-2.txt Ver ficheiro

@@ -0,0 +1 @@
IHDXUVZKRISCBNJWBXIDUWVVODUBPRFQRIRGBUR