wip
This commit is contained in:
		
							parent
							
								
									0bf405d961
								
							
						
					
					
						commit
						89bc0976f7
					
				
					 1 changed files with 17 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -4,6 +4,7 @@ from hashlib import sha3_256
 | 
			
		|||
from itertools import count
 | 
			
		||||
from Crypto.Cipher import ChaCha20
 | 
			
		||||
from math import floor, ceil
 | 
			
		||||
from time import sleep
 | 
			
		||||
 | 
			
		||||
def chacha_bits(input, bit_count):
 | 
			
		||||
    zerobyte = (0).to_bytes(length=1, byteorder='big')
 | 
			
		||||
| 
						 | 
				
			
			@ -11,22 +12,34 @@ def chacha_bits(input, bit_count):
 | 
			
		|||
    i = 0
 | 
			
		||||
 | 
			
		||||
    while True:
 | 
			
		||||
        print('-----------------------------')
 | 
			
		||||
        start_bit = bit_count * i
 | 
			
		||||
        start_byte = start_bit // 8
 | 
			
		||||
        start_padding = start_bit % 8
 | 
			
		||||
        print('start_bit', start_bit)
 | 
			
		||||
        print('start_byte', start_byte)
 | 
			
		||||
        print('start_padding', start_padding)
 | 
			
		||||
 | 
			
		||||
        end_bit = bit_count * i + bit_count
 | 
			
		||||
        end_byte = end_bit // 8
 | 
			
		||||
        end_padding = 8 - (end_bit % 8)
 | 
			
		||||
        print('end_bit', end_bit)
 | 
			
		||||
        print('end_byte', end_byte)
 | 
			
		||||
        print('end_padding', end_padding)
 | 
			
		||||
        
 | 
			
		||||
        byte_count = end_byte - start_byte
 | 
			
		||||
        byte_count = (end_byte - start_byte) + 1
 | 
			
		||||
        print('byte_count', byte_count)
 | 
			
		||||
 | 
			
		||||
        cipher.seek(start_byte)
 | 
			
		||||
        ciphertext = cipher.encrypt(zerobyte*byte_count)
 | 
			
		||||
        print('ciphertext', bin(int.from_bytes(ciphertext, byteorder='big')))
 | 
			
		||||
        shifted_ciphertext = int.from_bytes(ciphertext, byteorder='big') >> end_padding
 | 
			
		||||
        print('shifted_ciphertext', bin(shifted_ciphertext))
 | 
			
		||||
        
 | 
			
		||||
        bit_mask = int('1'*bit_count, 2)
 | 
			
		||||
        print('bit_mask', bin(bit_mask))
 | 
			
		||||
        masked_ciphertext = shifted_ciphertext & bit_mask
 | 
			
		||||
        print('masked_ciphertext', bin(masked_ciphertext))
 | 
			
		||||
 | 
			
		||||
        yield masked_ciphertext
 | 
			
		||||
        i += 1
 | 
			
		||||
| 
						 | 
				
			
			@ -46,5 +59,5 @@ def derive_string(input, length, choices):
 | 
			
		|||
    return ''.join(next(get_character) for i in range(length))
 | 
			
		||||
 | 
			
		||||
print(
 | 
			
		||||
    derive_string(b'12345', length=100, choices='abcde12345')
 | 
			
		||||
    derive_string(b'12345', length=100, choices='abcdefghijklmnopqrstuvwxyz0123456789')
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue