Skip to content

Instantly share code, notes, and snippets.

@drcircuit
Last active May 23, 2023 09:29
Show Gist options
  • Select an option

  • Save drcircuit/1d82878094ba4a8ff2e9c5516a43ccf2 to your computer and use it in GitHub Desktop.

Select an option

Save drcircuit/1d82878094ba4a8ff2e9c5516a43ccf2 to your computer and use it in GitHub Desktop.
#ascii
def read(file):
with open(file, 'r') as file:
decimals = file.read().split()
ascii = [chr(int(decimal)) for decimal in decimals]
mesage = ''.join(ascii)
print(mesage)
read('demofile.txt')
#base64
import base64
with open('basejump.txt','r') as file:
bstr = file.read().strip()
decode = base64.b64decode(bstr).decode("utf-8")
print(decode)
#hex
with open("hexy.txt", "r") as file:
hex = file.read().split()
chars = [chr(int(hexnum, 16)) for hexnum in hex]
print("".join(chars))
# AES
import binascii
from pwn import xor
with open("output.txt","rb") as f:
enc_quote = binascii.unhexlify(f.readline().strip())
enc_flag = binascii.unhexlify(f.readline().strip())
quote = f.readline().strip()
print(f"{enc_quote=}")
print(f"{enc_flag}")
print(f"{quote=}")
bb = xor(quote, enc_quote)
print(f"{bb=}")
ff = xor(enc_flag, bb)
print(f"{ff=}")
blob = xor(enc_quote, enc_flag)
flag = xor(blob, quote)
print(f"{flag=}")
# DES
import os
with open("words.txt", "r") as words_file:
word_array = words_file.read().splitlines()
print(f"Trying: {len(word_array)} passwords")
i = 0
for word in word_array:
i += 1
os.system(f"openssl enc -des -d -in encrypted.des -out result.txt -pbkdf2 -pass pass:{word} > /dev/null 2>&1")
with open("result.txt", "rb") as pfile:
try:
plaintext = pfile.read()
except:
continue
if all(32 <= byte < 127 or byte in (9, 10, 13) for byte in plaintext[:64]):
print(f"After {i} of {len(word_array)} passwords, we cracked it!")
print("Valid decryption:")
print("Passphrase:", word)
print("Plaintext:", plaintext.decode("utf-8", errors="ignore"))
break
if i % 100 == 0 or i == len(word_array):
print(f"Tried: {i} og {len(word_array)} passwords")
#RSA
#Fermat factorization:
import gmpy2
from Crypto.Util.number import *
def fermat_factor(n):
print(n)
assert n % 2 != 0
a = gmpy2.isqrt(n)
b2 = gmpy2.square(a) - n
for i in range(100000000):
a += 1
b2 = gmpy2.square(a) - n
if gmpy2.is_square(b2):
p = a + gmpy2.isqrt(b2)
q = a - gmpy2.isqrt(b2)
return True,(int(p), int(q))
return False,()
#RSA Decryption
#bignumbers
#n = 23135514747783882716888676812295359006102435689848260501709475114767217528965364658403027664227615593085036290166289063788272776788638764660757735264077730982726873368488789034079040049824603517615442321955626164064763328102556475952363475005967968681746619179641519183612638784244197749344305359692751832455587854243160406582696594311842565272623730709252650625846680194953309748453515876633303858147298846454105907265186127420148343526253775550105897136275826705375222242565865228645214598819541187583028360400160631947584202826991980657718853446368090891391744347723951620641492388205471242788631833531394634945663
#e = 65537
#c = 17830167351685057470426148820703481112309475954806278304600862043185650439097181747043204885329525211579732614665322698426329449125482709124139851522121862053345527979419420678255168453521857375994190985370640433256068675028575470040533677286141917358212661540266638008376296359267047685745805295747215450691069703625474047825597597912415099008745060616375313170031232301933185011013735135370715444443319033139774851324477224585336813629117088332254309481591751292335835747491446904471032096338134760865724230819823010046719914443703839473237372520085899409816981311851296947867647723573368447922606495085341947385255
# TEST 'hello'
n = 535110612871528225512272684507030801
c = 304200715058485001796472321545733927
e = 65537
can_factor ,(p, q) = fermat_factor(n)
print(f"{p=}")
print(f"{q=}")
if can_factor:
phi = (p-1)*(q-1)
d = inverse(e,phi)
m = pow(c,d,n)
print(long_to_bytes(m))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment