initial commit

This commit is contained in:
Dominik Moritz Roth 2020-05-29 21:20:50 +02:00
commit 3c169e270a
5 changed files with 276 additions and 0 deletions

Binary file not shown.

180
break.py Normal file
View File

@ -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()<float("0."+"9"*less):
return
global s
maxLen = 10
if status != "":
s = status
cls()
print(knownDec[:maxLen*BS])
for bi,b in enumerate(enc):
if bi>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)

48
lazarus.py Normal file
View File

@ -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)

BIN
lazarus.pyc Normal file

Binary file not shown.

48
note.py Normal file
View File

@ -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)