Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Custom encryption algorithm in python [closed]

$
0
0

I have made a string encryption method, but i can't find out how to make a decryption method. My encryption function is below (in python)

def encrypt(text, key):        cmp=["q","w","e","r","t","y","i","u","p","o","s","a","f","d","h","g","k","j","k","l","z","x","c","v","b","n","m","Q","l","E","W","T","R","U","Y","O","I","A","P","D","S","G","F","J","H","L","K","X","Z","V","C","N","B","`","M","2","1","4","3","6","5","8","7","0","9","=","-","!","~","#","@","%","$","&","^","(","*","_",")"," ","+","[","]","\\","{","}","|",",",".","/","<",">","/"]        md={}        c=0        for id in cmp:            md[id]=c            c+=1        keyInFigs=0        for char in key:            keyInFigs+=md[char]        textObj=text        textInFigs=""        for char in textObj:            textInFigs+=str(md[char])+" "        textInFigs=textInFigs.removesuffix(" ")        output=""        for char in textInFigs.split():            output += str(int(char) * keyInFigs) +" "        return output

and my decryption algorithm:

def encrypt(text, key):        cmp=["q","w","e","r","t","y","i","u","p","o","s","a","f","d","h","g","k","j","k","l","z","x","c","v","b","n","m","Q","l","E","W","T","R","U","Y","O","I","A","P","D","S","G","F","J","H","L","K","X","Z","V","C","N","B","`","M","2","1","4","3","6","5","8","7","0","9","=","-","!","~","#","@","%","$","&","^","(","*","_",")"," ","+","[","]","\\","{","}","|",",",".","/","<",">","/"]        md={}        c=0        for id in cmp:            md[id]=c            c+=1        keyInFigs=0        for char in key:            keyInFigs+=md[char]        textObj=text        textInFigs=""        for char in textObj:            textInFigs+=str(md[char])+" "        textInFigs=textInFigs.removesuffix(" ")        output=""        for char in textInFigs.split():            output += str(int(int(char) / keyInFigs))        return output

Thank you for help in advance.


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>