Package: cha-hashing
READ METhis was made for fun and learning cryptography and python.
Everything here is not for real use-cases.
Keep in mind that the functions here are probably insecure.
They went through 0 security checks, and were made without thinking of the security side of things.Hashing use casesDetecting duplicated records.Locating points that are near each other.Verifying message integrity.Verifying passwords.Installationpippip install cha-hashinghow to useimport CHA *fromCHAimportFeistelNfromCHAimportCHAObjectfromCHAimportHashMakerfromCHAimportPiranhafromCHAimportPEMFileor justfrom CHA import *How RA worksThe shuffle algorithmdefshuffle(to_shuffle_list:list):to_shuffle_list=to_shuffle_list.copy()to_append_size=to_shuffle_list[0]a=[]fori1inrange(to_append_size%len(to_shuffle_list)):a.append(to_shuffle_list.pop(0))to_shuffle_list.reverse()fori2ina:to_shuffle_list.append(i2)e=[]fori3,chinenumerate(to_shuffle_list):ifi3%2==0:e.append(to_shuffle_list.pop(i3))fori4ine:to_shuffle_list.append(i4)returnto_shuffle_listStep One: EncipherThe function enciphers each letter with a letter in the shuffle list if it exists there, then shifts the letters in the shuffle list by the ord of c ** ord c each time.for c in message:
    for i in range(0, pow(ord(c), ord(c), len(shuffle_list))):
        first = shuffle_list.pop(0)
        shuffle_list.append(first)
    ord_shuffle_list = [ord(c) for c in shuffle_list]
    shuffled = shuffle(ord_shuffle_list)
    shuffle_list = [chr(c) for c in shuffled]
    if c in characters and c in shuffle_list:
        index = characters.index(c)
        original_message.append(shuffle_list[index])
    else:
        original_message.append(c)Step Two: Paddingbinary_formatted_message = [format(ord(c), 'b') for c in original_message]

            amount_to_shift = len(padding_list) - len(binary_formatted_message)
            if amount_to_shift <= 0: amount_to_shift *= -1
            shift_must = ord(original_message[0]) if len(original_message) > 0 else shift_must_if_om0
            amount_to_shift += shift_must
            binary_formatted_message.extend(padding_list)Step Three: Keyingkey = binary_formatted_message.copy()
            for i in range(0, amount_to_shift):
                if times % rev_every == 0:
                    key.reverse()
                first = key.pop(0)
                key.append(first)
            if key == binary_formatted_message:
                first = key.pop(0)
                key.append(first)Step Four: XORingIn this step we XOR the ciphertext with our keybinary_formatted_message = list(int(c, 2) for c in binary_formatted_message)
key = list(int(c, 2) for c in key)
xored = []
for i in range(len(binary_formatted_message)):
    xored.append(binary_formatted_message[i] ^ key[i])Step Five: Repeat and shift paddingbinary_formatted_message = list(int(c, 2) for c in binary_formatted_message)
key = list(int(c, 2) for c in key)
xored = []
for i in range(len(binary_formatted_message)):
    xored.append(binary_formatted_message[i] ^ key[i])Step Six: FinalWe join this large list, turn that into an int, and then we return a CHAObject object of its_xored = [str(n) for n in xored]
s = ''
for string in s_xored:
    s += string.strip("-")
s = s[0:size_limit_of_0]
for i in range(pow(amount_to_shift, amount_to_shift, len(padding_list))):
    intL = [int(c, 2) for c in padding_list]
    padding_list = shuffle(intL)
    padding_list = [format(c, 'b') for c in padding_list]
message = sCHA - Customizable Hashing AlgorithmCHA works the same way as RA, but customizable. so I'll only talk about the customization.messageThe plaintext that enters the function.paddingThe padding as a byte string separated by a space, like :'01110011 00110011 11000110'.
this will be appended to the messageshaffle_listThe letter shuffle listCheck the encipher step in the RAsize_limit_of_0how many 0 are allowedrepnumber of repetitionschar_setAdditional chars used in the shuffle_listshift_must_if_om0shift_must = ord(om[0]) if len(om) > 0 else shift_must_if_om0rev_everyWill preform some additional tasks with every time % $rev_every == 0CHABLike CHA but the message is in bytesHMACSyntax for hmac:fromCHAimportFeistelNfromCHAimportCHAFHMAC# our secret key:secret=b'test'# messagemsg=b'secret msg'# creating a hmac objhmac_obj=CHAFHMAC(secret,func=FeistelN.fRAB_with_nonce(secret))hmac_obj.update(msg)# getting a macmac=hmac_obj.hexdigest()print(mac)# verifying a macprint(hmac_obj.verify(mac))Creating your own algorithm using HashMakerRandomShaffleThis function will help you make your own random shuffled charset (secrets.SystemRandom().shuffle(letters)but with built-in langs)
returns a stringRandomBitsThis function will help you make your own random bits.
returns a string or a listhow_many:
how many groups of bits do you want.group:
how many in one group, 8 for a bytehow_to_format:
Can be " " or "l". 
"l" for a list.
" " for a " ".join(bits)get_CHA_argsThis function will print the syntax needed. and return the padding, and shuffle key.NoteThere is a chance that some padding or shuffle_key have a backdoor in them (I don't know if there really is, but probably).Encryption with CHACHA can be also used as an encryption function using the feistel cipher (see CHAF)for example:def fCHA(b):
        padding, shuffle_list, size, rep, char_set, smio = CHAObject.get_RA_args()
        return CHAObject.CHAB(b,padding,shuffle_list, 128, 16, '', 153)
    s = input("Enter an input:\n").encode()
    e = FeistelN().DE(s,  8, fCHA)
    print(e)
    d = FeistelN().DE(e,  8,fCHA, 'd')
    print(d)to make your own:define a functiondefine a function using this templatedef fCHA(b):
        padding, shuffle_list, size, rep, char_set, smio = CHAObject.get_RA_args()
        return CHAObject.CHAB(b,padding,shuffle_list, 128, 16, '', 153)the function needs to return bytes, here we're using CHAB with the RA args.Call DEthen the Feistel function uses 64 bits everytime, I configed the DE function on the FeistelN class
to do this automatically.mode 'e'this will return a list of hexesmode 'd'will return the stringFeistel Cipher - ComputerphileBlackFrogThis is an asymmetric encryption algorithmKey generation:
â€”---------------------------------------------------------------

Let n = large prime number

Pick e such that gcd(e,n) == 1 and e < n and e is prime
d = e**-1 % n
N = n * e * random
E = e**d % N
D = d**d % n

Public key: {E,N}
Private key: {n,d,e,D}

Encryption:
â€”---------------------------------------------------------------

ciphertext = message*E % N

Decryption:
â€”---------------------------------------------------------------
message = ciphertext*D % nGenerate keysreturns two keys, one public, one privateEncryptEncrypts bytes with public key and returns cipher text as bytesDecryptDecrypt bytes with private key and returns message text as bytesPiranhaI made this cipher using the RAB-Feistel network.I made this to learn aboutmodes of operation.Right now the available modes are:ECBCBCCTREAA (My Encrypt and Authenticate, not EAX)key = b"super secret key"
    msg = b'Test message'
    # EBC
    cipher = Piranha(key, Piranha.EBC)
    c = cipher.encrypt(msg)
    print(c)
    cipher = Piranha(key, Piranha.EBC)
    m = cipher.decrypt(c)
    print(m)

    # CBC
    cipher = Piranha(key, Piranha.CBC)
    paddedMsg = Piranha.pad(msg, Piranha.BlockSize)
    c = cipher.encrypt(paddedMsg)
    print(c)
    cipher = Piranha(key, Piranha.CBC, iv=cipher.iv)
    m = Piranha.unpad(cipher.decrypt(c))
    print(m)

    # CTR
    cipher = Piranha(key, Piranha.CTR)
    paddedMsg = Piranha.pad(msg, Piranha.BlockSize)
    c = cipher.encrypt(paddedMsg)
    print(c)
    cipher = Piranha(key, Piranha.CTR, iv=cipher.iv)
    m = Piranha.unpad(cipher.decrypt(c))
    
    # EAA
    key = b"key"
    m = Piranha.pad(b'test')
    cipher = Piranha(key, Piranha.EAA, data=m)
    a = cipher.encrypt(m)
    print(a)
    cipher = Piranha(key, Piranha.EAA, iv=cipher.iv, data=a)
    print(Piranha.unpad(cipher.decrypt(a)))KRY and KRHASHI made this cipher using the KRHASH-Feistel network.I made this to learn aboutmodes of operation.Right now the available modes are:ECBCBCCTREAA (My Encrypt and Authenticate, not EAX)Works similar to Piranha, just replace Piranha with KRYCowCowModesI made this cipher using the CowCow-sp network.I made this to learn aboutmodes of operation.Right now the available modes are:ECBCTREAA (My Encrypt and Authenticate, not EAX)Works similar to Piranha, just replace Piranha with CowCowModesModes (Build you own)Right now the available modes are:ECBCBCCTREAA (My Encrypt and Authenticate, not EAX)Warning: do not init directly, use Modes.new()Notes:This is insecure! I made everything for fun and learning! Do not use in real usecasesPS: I know my code looks bad