add xmasspirit
This commit is contained in:
25
crypto/XMASSpirit/challenge.py
Normal file
25
crypto/XMASSpirit/challenge.py
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import random
|
||||
from math import gcd
|
||||
|
||||
def encrypt(dt):
|
||||
mod = 256
|
||||
while True:
|
||||
a = random.randint(1,mod)
|
||||
if gcd(a, mod) == 1: break
|
||||
b = random.randint(1,mod)
|
||||
|
||||
res = b''
|
||||
for byte in dt:
|
||||
enc = (a*byte + b) % mod
|
||||
res += bytes([enc])
|
||||
return res
|
||||
|
||||
dt = open('letter.pdf', 'rb').read()
|
||||
|
||||
res = encrypt(dt)
|
||||
|
||||
f = open('encrypted.bin', 'wb')
|
||||
f.write(res)
|
||||
f.close()
|
||||
8
crypto/XMASSpirit/decrypt.py
Normal file
8
crypto/XMASSpirit/decrypt.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import random
|
||||
from math import gcd
|
||||
|
||||
def decrypt(dt):
|
||||
mod = 256
|
||||
|
||||
f = open('encrypted.bin', 'wb').read()
|
||||
print(f)
|
||||
BIN
crypto/XMASSpirit/encrypted.bin
Normal file
BIN
crypto/XMASSpirit/encrypted.bin
Normal file
Binary file not shown.
Reference in New Issue
Block a user