Skip to content

Instantly share code, notes, and snippets.

View GordonOus's full-sized avatar

GordonOus

View GitHub Profile
import math
from random import randint, seed
from time import time, process_time
import string
strchr = lambda x: chr(x)
strbyt = lambda x, y=0: ord(x[y])
bitlst = lambda x, y: x << y
bitrst = lambda x, y: x >> y
bitext = lambda x, y, z=1: bitrst(x, y) & int(math.pow(2, z) - 1)
@GordonOus
GordonOus / adrien_sign.py
Created October 4, 2021 14:13
cryptohack adrien_signs
def pohligHellmanPGH(p,g,h):
#p is the modulus
#g is the argument (a)
#h is the equivalence class i.e the result of pow(g,e,p). e is what we are looking for
F=IntegerModRing(p)
g=F(g)
h=F(h)
G=[]
H=[]
X=[]
@GordonOus
GordonOus / diffusion_permutation.py
Created September 25, 2021 18:13
cryptohack symmetric crypto series
def shift_rows(s):
s[0][1], s[1][1], s[2][1], s[3][1] = s[1][1], s[2][1], s[3][1], s[0][1]
s[0][2], s[1][2], s[2][2], s[3][2] = s[2][2], s[3][2], s[0][2], s[1][2]
s[0][3], s[1][3], s[2][3], s[3][3] = s[3][3], s[0][3], s[1][3], s[2][3]
def inv_shift_rows(s):
tmp = s[13]
s[13] = s[9]
s[9] = s[5]
ssh-keygen -e -f 'bruce_rsa_6e7ecd53b443a97013397b1a1ea30e14.pub' -m 'PKCS8' > bruce.pub
openssl rsa -pubin -in bruce.pub -noout -modulus | cut -d '=' -f2 | xargs echo "ibase=16; $1"| bc | tr -d '\' | tr -d '\n'
ssh-keygen -e -f 'bruce_rsa_6e7ecd53b443a97013397b1a1ea30e14.pub' -m 'PKCS8' > bruce.pub
openssl rsa -pubin -in foo.pub -noout -modulus | cut -d '=' -f2 | xargs echo "ibase=16; $1"| bc | tr -d '\' | tr -d '\n'
import numpy as np
from PIL import Image
img1 = Image.open('lemur.png')
img2 = Image.open('flag.png')
n1 = np.array(img1)*255
n2 = np.array(img2)*255
#our images have a mode of RGB which is assumed to be an 8-bit int
import gmpy2
from Crypto.Util.number import long_to_bytes, bytes_to_long
from binascii import unhexlify
flag = open('output.txt','r').read().strip().split(' ')[1]
ciphertext = bytes_to_long(flag)
e = 3
#Fist method of getting cube root of ciphertext
gmpy2.get_context().precision = 4096
import time
import random
from pwn import *
def gen_seeds(s):
return list(range((s - 20),(s + 20)))
possible_seeds = gen_seeds(int(time.time()))
conn = remote('IP ADDRESS',PORT)
from binascii import unhexlify
enc_flag = 'Put the encrypted flag extracted from the pcap hear'
ct = 'the First Ciphertext we find'
ct2 = 'the second Ciphertext we find'
flag = ''
#Note the length of all the above texts are 36 bytes after decoding from ascii
for i,j in enumerate(ct):
flag += chr(j ^ ct2[i] ^ enc_flag[i])
import string
from binascii import unhexlify
encrypted = unhexlify(open('msg.enc','r').read())
plaintext = []
#brute force the encryption logic
for b in encrypted:
for ch in string.printable:
if ((123 * ord(ch) + 18) % 256 == b):
plaintext.append(ch)