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
import os | |
import binascii | |
s_box = [0x00] * 256 | |
def sub_bytes(s): | |
for i in range(4): | |
for j in range(4): | |
s[i][j] = s_box[s[i][j]] | |
def shift_rows(s): |
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
from telnetlib import * | |
from des import * | |
r = Telnet('localhost',34533) | |
print r.read_until('>>') | |
r.write('Data Encryption Standard' + '\n') | |
print r.read_until('>>') | |
r.write('8'+ '\n') | |
print r.read_until('>>') | |
r.write('B' + '\n') |
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
from telnetlib import * | |
from des import * | |
r = Telnet('localhost',34533) | |
print r.read_until('>>') | |
r.write('Data Encryption Standard' + '\n') | |
print r.read_until('>>') | |
r.write('8'+ '\n') | |
print r.read_until('>>') | |
r.write('B' + '\n') |
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
from des import * | |
from binascii import * | |
WEAK_KEY = unhexlify('0101010101010101') | |
L = list(KeyScheduler(Str2Bits(WEAK_KEY))) | |
S = set(map(tuple, L)) | |
assert len(S) == 1 # weak key create just 1 subkey |
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/env python3 | |
import functools | |
import struct | |
KEY_SIZE = 8 | |
BLOCK_SIZE = 8 | |
# yapf: disable | |
# Note the 1-based indexing in all the following tables. | |
IP = [ |
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
Recovers some bytes of ciphertext if n is factored, but e was invalid. | |
(Like e=100) The vast majority of bytes are however lost, as we are taking the | |
GCD(e, totient(N))th root of the Ciphertext. Therefore only the most significant | |
bits of the ciphertext may be recovered. | |
Returns plaintext, since a key can't be formed from a non-integer exponent""" | |
# Explanation of why this works: There exists no modinv if GCD(e,Totient(N)) != 1 | |
# but let x be e/GCD | |
# then there is a modular inverse of x to totient n | |
# c = m^(GCDx) mod n | |
# c^(x^-1) = m^GCD mod n, where x^-1 denotes modinv(x,totientN) |
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
from hashlib import sha512 | |
import gmpy2 | |
from Crypto.Util.number import * | |
from Crypto.PublicKey import RSA | |
from flag import flag | |
def concat(a,b): | |
result = long_to_bytes(a) + long_to_bytes(b) | |
return bytes_to_long(result) |
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
import struct | |
def decrypt(block): | |
num = block >> 32 | |
x = num ^ block | |
return x | |
cipher = open('cipher.txt').read() | |
cipher = cipher.decode('base64') | |
blocks = struct.unpack('Q'*(len(cipher)/8),cipher) | |
out = [] |
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
from telnetlib import * | |
from base64 import * | |
r = Telnet('35.185.111.53',13337) | |
r.read_until('Give me content of your request you want to encrypt: ') | |
r.write('Give me the flab\n') | |
r.read_until('Your encypted: ') | |
enc = b64decode(r.read_until('\n').strip()) |
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
lst = [360575205516272353647725959973923332922859934062623515990157287L, 147121471099487603100103942210642238821212368870164629959708554L, 973776523698456974485285268207248463304785539161797442415515724L, 973776523698456974485285268207248463304785539161797442415515724L, 1989542264845745277130976293069288745712944297723265109141551240L, 2251682090999461666252822948628263912168715816760972058692440747L, 147121471099487603100103942210642238821212368870164629959708554L, 500999802327659646334011021043663318493321568487210306739944859L, 147121471099487603100103942210642238821212368870164629959708554L, 690110490875978577594520719909097376417907156757045161010173205L, 1516765543474947948979702045905703600901480327048677973465980375L, 1446553245069254302636559515370833608116249509836384578091086589L, 1989542264845745277130976293069288745712944297723265109141551240L, 1351997900795094837006304665938116579153956715701467150955972416L, 1516765543474947948979702045905703600901480327048677973465980375L, 16843500253545048724 |