From 3c169e270a6fb910103d7281c2f25e6e76acebc1 Mon Sep 17 00:00:00 2001 From: Dominik Roth Date: Fri, 29 May 2020 21:20:50 +0200 Subject: [PATCH] initial commit --- __pycache__/main.cpython-36.pyc | Bin 0 -> 17650 bytes break.py | 180 ++++++++++++++++++++++++++++++++ lazarus.py | 48 +++++++++ lazarus.pyc | Bin 0 -> 2768 bytes note.py | 48 +++++++++ 5 files changed, 276 insertions(+) create mode 100644 __pycache__/main.cpython-36.pyc create mode 100644 break.py create mode 100644 lazarus.py create mode 100644 lazarus.pyc create mode 100644 note.py diff --git a/__pycache__/main.cpython-36.pyc b/__pycache__/main.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..44726a1b28fcd3aa2ff929d3af8dbd1f2d780d06 GIT binary patch literal 17650 zcmeHPTWlQHd7j(u&MueBizw<6)uAOtF&#%2ijpN&b!khM?~GijR=TlGEq8|EQsi=Z zW@xX7*|asCL{3pex%8H_Zi1$*6QD&3^dUg|5cDYs`jCe{6a%y`1qvt)TA(fR;5?+? z_n(>Bi|9BBT%bj}#GIXT=FH4F|M|}M|K~sd^5pPv>FfT!j~#l}F#gHt`Pew0!x6lR zybWv{chMbGsxVHVH+jXF-cv^#vrpFY zB^3Ea)%1+2Spy-9D+ z>qd3h+lvbcMz>kw07w{d-A@R(}Sb*@5nx2i+x?v!-+Xo`^qVdv1 z2W2bviWBA{d)wSLO=IJ}YevNSdC$OWocX(WjB(d6k?=Lsg}4-iH5D$@muo5>uC2C~ zYm0uk5Hz;@c!=r3Qmr1YtJuEj--`3KR?BaCvAwRmIM-Zn*8OQGb^?EONfq%tRYnp! zi?>4mYla#@=ItkrEw8Wn$GmlKy?rcb)>_A!emktMu5WrDuCF%yW_awx@niF8*|E!N zeZ{Yb!Ld~>kYj7LM)PRvR_rb;G@6ZYVZp*(bHdyjO+o`!sR zmq=S=Y|Se+aJm?~H~i*8eRI)QE(%lu2}HHH-i}?!QeVl0rb?_c#5-*@%&J8Z?`k6m z6+0`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@gS^2`d)FHq&9p&9E+thN9(gDe_^ZVEz4yks1>aZF#C7bNRfLWW^K-Rv1BjDh} z7_-_BVcuidg}m?MMhs1{G)|Jx-Uc7YLVPq?)TTyQK|5>MI{ZF3R611S4P<+|ki^xz zhSI9tYBYD^bot)~@=LG#*rU`M8|6l)5Ig$>r6^Un&G~ga4PVdmE4L#o{*0~YicHRg zB)^6Wd-)bh14c+rv1A?*Yvf;vvDI)EUBAJy&oH5xBC1r+XTnDA-03B;dtL{IbMr%o cs8oK{I9?g59IK309>Dqe%I=C=DOC3S7c8PjLI3~& literal 0 HcmV?d00001 diff --git a/break.py b/break.py new file mode 100644 index 0000000..167d8f2 --- /dev/null +++ b/break.py @@ -0,0 +1,180 @@ +import os +import sys +import time +import random +import hashlib +import itertools +from base64 import b64encode as b64enc, b64decode as b64dec + +BS = 16 +iv = "0"*BS # set to "" if not known + +class bc: + HEADER = '\033[95m' + OKBLUE = '\033[94m' + OKGREEN = '\033[92m' + WARNING = '\033[93m' + FAIL = '\033[91m' + ENDC = '\033[0m' + BOLD = '\033[1m' + UNDERLINE = '\033[4m' + +def p(t): + sys.stdout.write(t) + + +s = "" +def printScreen(enc,dec,match,status="",less=False): + if less and random.random()maxLen: + break + for ni,n in enumerate(b): + if dec[bi][ni]=="0": + if match!=0: + matchInds = [] + for m in match[ni]: + for i in m[1]: + matchInds.append(i) + if bi in matchInds: + #p(bc.OKBLUE+b64enc(n)[0]+bc.ENDC) + p(b64enc(n)[0]) + else: + #p(b64enc(n)[0]) + p(bc.FAIL+"#"+bc.ENDC) + else: + p(bc.OKGREEN+dec[bi][ni]+bc.ENDC) + print("\n\n"+s+"\n\n") + #time.sleep(0.01) + +def cls(): + os.system('cls' if os.name=='nt' else 'clear') + +def sxor(s1,s2): + return ''.join(chr(ord(a) ^ ord(b)) for a,b in zip(s1,s2)) + +def main(enc): + c = [list(enc[i*BS:][:BS]) for i in range(int(ceil(float(len(enc))/BS)))] + enc = c + dec = [] + for i in enc: + dec.append(["0"]*BS) + printScreen(enc,dec,0,"Cross-Entropy-Mapping") + # nugget 1 nugget 2 + # [ [[char,block],...] , [...] , ... ] + seen = [] + # nugget 1 nugget 2 + # [ [[char,[index1,index2,...],...] , [...] , ... ] + match = [] + + # [[clash,indN,indA,indB],...] + tron = [] + for i in range(BS): + match.append([]) + seen.append([]) + for bi,b in enumerate(enc): #for every block + for ni,n in enumerate(b): #for every nugget + for mi,m in enumerate(match[ni]): + if m[0]==n: # Match already exists, add our new one + m[1].append(bi) # add our Block-Index to the Match + printScreen(enc,dec,match,"",2) + break + else: # No existing Match found; Searching for new one + for si,s in enumerate(seen[ni]): + if s[0]==n: #Found dat Match + # char,[bIndex Seen, bIndex New] + match[ni].append([n,[s[1],bi]]) + printScreen(enc,dec,match,"",2) + break + else: # No Match, Char not in seen + # char, bIndex + seen[ni].append([n,bi]) + + printScreen(enc,dec,match,"Calculating Trons...") + for ni,n in enumerate(match): #for every nugget + for mi,m in enumerate(n): #for every match + for indexA,indexB in itertools.combinations(m[1],2): #for every bIndex-Pair + if indexA==0: + if len(iv)!=0: + tron.append([ sxor(enc[indexB-1][ni],iv), ni, [indexA, indexB]]) + else: + tron.append([ sxor(enc[indexA-1][ni],enc[indexB-1][ni]), ni, [indexA, indexB]]) + + printScreen(enc,dec,match,"Constructing Matrix") + matrix = [] + for i in range(len(enc)*BS): + matrix.append([]) + for j in range(128): + matrix[i] = [1]*128 + + printScreen(enc,dec,match,"Planting Seeds...") + for ti,t in enumerate(tron): + bin = '{0:07b}'.format(ord(t[0])) + for b in [0,1]: + if bin[:2]=="00": + # is 00****** + # but to be valid, it has to be 001***** -> min 32 + for i in range(32): + matrix[t[2][b]*8+t[1]][i] = 0 + elif bin[:2]=="10": + # is 10****** + # first bit is not allowes to flip + for i in range(64,128): + matrix[t[2][b]*8+t[1]][i] = 0 + elif bin[:2]=="11": + # is 11****** + # first 2 bits are not allowes to flip + for i in range(96,128): + matrix[t[2][b]*8+t[1]][i] = 0 + elif bin[:2]=="01": + # is 01****** + # second bit is only allowed to flip, + # if first bit flips + for i in range(32,64): + matrix[t[2][b]*8+t[1]][i] = 0 + + legals = [] + legals.append([45,46,47]) + legals.append(range(65,90)) + legals.append([95]) + legals.append([97,122]) + + tronHistory = [] + + printScreen(enc,dec,match,"Growing Seeds...") + while True: + p(".") + hash = hashlib.sha256(str(tron)).hexdigest() + if hash in tronHistory: + break + tronHistory.append(hash) + for ti,t in enumerate(tron): + for direction in [0,1]: + for possibilityA,avaibleA in enumerate(matrix[t[2][direction]*8+t[1]]): + if avaibleA: + for possibilityB,avaibleB in enumerate(matrix[t[2][direction]*8+t[1]]): + if avaibleB: + if (possibilityA ^ possibilityB) not in legals: + matrix[t[2][direction]*8+t[1]][possibilityA] = 0 + matrix[t[2][direction]*8+t[1]][possibilityB] = 0 + for m in matrix: + l = 0 + for i in m: + if i: + l+=1 + if l==1: + print("Yay!") + +if __name__=="__main__": + from lazarus import * + lazarus = Lazarus("This is a safe Password") + knownDec = "This is a very very long text message, that I use to text my text. If you read this text, dont think it is your text just because you read it, it is still my text! So: Fuck of and get you own text, if you want one, asshole..."*200 + enc = lazarus.enc(knownDec) + main(enc) diff --git a/lazarus.py b/lazarus.py new file mode 100644 index 0000000..4755c18 --- /dev/null +++ b/lazarus.py @@ -0,0 +1,48 @@ +from math import ceil +from urllib2 import quote, unquote +from base64 import b64encode as b64enc + +class Lazarus(): + def __init__(self, key): + self.key = key + self.BS = 16 + self.iv = "0"*self.BS + + def enc(self, plaintext): + t = quote(plaintext) + prevBlock = self.iv + c = "" + for i in range(int(ceil(float(len(t))/self.BS))): + block = t[i*self.BS:][:self.BS] + prevBlock=self._sxor(self._rc4(block),prevBlock) + c+=prevBlock + return c + + def dec(self, ciphertext): + c = ciphertext + prevBlock = self.iv + t = "" + for i in range(int(ceil(float(len(c))/self.BS))): + block = c[i*self.BS:][:self.BS] + t+=self._rc4(self._sxor(block,prevBlock)) + prevBlock = block + return unquote(t) + + def _sxor(self, s1, s2): + return ''.join(chr(ord(a) ^ ord(b)) for a,b in zip(s1,s2)) + + def _rc4(self, data): + box = list(range(256)) + x = 0 + for i in range(256): + x = (x + box[i] + ord(self.key[i % len(self.key)])) % 256 + box[i], box[x] = box[x], box[i] + x = 0 + y = 0 + out = [] + for char in data: + x = (x + 1) % 256 + y = (y + box[x]) % 256 + box[x], box[y] = box[y], box[x] + out.append(chr(ord(char) ^ box[(box[x] + box[y]) % 256])) + return ''.join(out) diff --git a/lazarus.pyc b/lazarus.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f5c678851839ed8e42ca17328ed7482bcdf33672 GIT binary patch literal 2768 zcmcImQEwYX5T5nf=Oi>Gv}w|`MF~iNU#OEPEiX|;(@01NEOe2GFhth*?wXu?_Stvq z%Bh^E@C%Umm%Q-<;QMCngg(F%w!L$+b9b||^UZu~@6XkhKY}MeM>6|(xPFaMeh(4j zXCxEp8)+LcoL3~PNZ*sTC;h6ltIq04R+GLj?K^_4EBgB!Vrpb6($Q2~-KnX<#@}ehaO6k@u5koX7d3 zSq{QsbC67Il;z|2%P32efo<;XHd}LB^M@kuC6O(gnM=(4`gC|{ne|R59i+C?;YuZi zm}Pu*zf3nxy5HZRSl#lqk*oPOuaG=Ut1=l1wt!6mJRoL$nN|c(;>U#4<$;?(9-qCE zs~Yc5A@%0^w!7|J;XPQER4&WZR|lS4R|HEPD%goE=$Go21>0IM^<&hpTzIZFlsx2aEe%1K^m@pX#mph0`U3bPc$EQAl_RWY>A zRwQqavOIdDwn$~FuDY}?4ms8iiv9y!O4gN_I{?i$`{to}Z0`OGd??o$aKdcf0%zXC z?mgiA{{qez2b?bo9MDlTX9xmH1rCrCGGK{CM=#|RxdV1E&)^HV4+kHS3+_;?Qea4M zm*PVTMdTxD+;qUs`3FkGKT3xeNkN!`2Yh6m;y%R&#U{jJQHhg?3(rvTZ&2AbD<&dr z9Ap%2svRhRp{L{t3PJ^uQ_wjTId%;*qYuqd#Oj_qD4~~o5J>mg7xD`_MDay4I5&8o zinifPOnx*YfKEc9o0g**dW$X!ZHByv9W^nrPj|JPLzUfyC9Py{9iAs(v0?FI2a}Sk z`*O>Ky&R3lINzm1jn6eDA1n8iH_QEn#iy0FJr7GIz6!r?F( z#KB`4cOdk?f~x=?lW}N6EskzJ(Ndjgr>lDDs(Ng7mFOZY7FQ-@rB5+RZb8gFknw%9 zYd*o1-&K(EJ@c`7W|XjINADo)C!LNZadkTVJRWD526~P?ge`bPp;Slrx52CSKmQvD zm`xH>$@M{8wdECjy_Q>6&p|%Y5AB6JNy*0JBFob5zB_i=k&0P2ER*L40ejZX^)H&P Yu-Hv#UJqR+U$D~jFU^|SFl&{+0eT!19smFU literal 0 HcmV?d00001 diff --git a/note.py b/note.py new file mode 100644 index 0000000..ec16674 --- /dev/null +++ b/note.py @@ -0,0 +1,48 @@ + +class AESModeOfOperationCBC(AESBlockModeOfOperation): + '''AES Cipher-Block Chaining Mode of Operation. + o The Initialization Vector (IV) + o Block-cipher, so data must be padded to 16 byte boundaries + o An incorrect initialization vector will only cause the first + block to be corrupt; all other blocks will be intact + o A corrupt bit in the cipher text will cause a block to be + corrupted, and the next block to be inverted, but all other + blocks will be intact. + Security Notes: + o This method (and CTR) ARE recommended. + Also see: + o https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher-block_chaining_.28CBC.29 + o See NIST SP800-38A (http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf); section 6.2''' + + + name = "Cipher-Block Chaining (CBC)" + + def __init__(self, key, iv = None): + if iv is None: + self._last_cipherblock = [ 0 ] * 16 + elif len(iv) != 16: + raise ValueError('initialization vector must be 16 bytes') + else: + self._last_cipherblock = _string_to_bytes(iv) + + AESBlockModeOfOperation.__init__(self, key) + + def encrypt(self, plaintext): + if len(plaintext) != 16: + raise ValueError('plaintext block must be 16 bytes') + + plaintext = _string_to_bytes(plaintext) + precipherblock = [ (p ^ l) for (p, l) in zip(plaintext, self._last_cipherblock) ] + self._last_cipherblock = self._aes.encrypt(precipherblock) + + return _bytes_to_string(self._last_cipherblock) + + def decrypt(self, ciphertext): + if len(ciphertext) != 16: + raise ValueError('ciphertext block must be 16 bytes') + + cipherblock = _string_to_bytes(ciphertext) + plaintext = [ (p ^ l) for (p, l) in zip(self._aes.decrypt(cipherblock), self._last_cipherblock) ] + self._last_cipherblock = cipherblock + + return _bytes_to_string(plaintext)