Answers for "python cipher decoder"

1

python automatic caesar cipher decrypt

x = input()
NUM_LETTERS = 26
def SpyCoder(S, N):
   y = ""
   for i in S:
      if(i.isupper()):
         x = ord(i)
         x += N
         if x > ord('Z'):
            x -= NUM_LETTERS
         elif x < ord('A'):
            x += NUM_LETTERS
         y += chr(x)
      else:
         y += " "
   return y

def GoodnessFinder(S):
   y = 0
   for i in S:
      if i.isupper():
         x = ord(i)
         x -= ord('A')
         y += letterGoodness[x]
      else:
         y += 1
   return y

def GoodnessComparer(S):
   goodnesstocompare = GoodnessFinder(S)
   goodness = 0
   v = ''
   best_v = S
   for i in range(0, 26):
     v = SpyCoder(S, i)
     goodness = GoodnessFinder(v)
     if goodness > goodnesstocompare:
         best_v = v
         goodnesstocompare = goodness
   return best_v


print(GoodnessComparer(x))
Posted by: Guest on May-11-2021
0

encoder and decoder code example python

import math

code = [10 , "abcdefghijklmnopqrstuvwxyz0123456789+-. _*/[](){},':;!@$฿%^&<>?=~`"]

def encode(val, charset):
    encoded = ""
    for idx in range(len(str(val))):
        tempEnc = encoded
        encoded = tempEnc + str(charset[0] + charset[1].index(str(val[idx])))
    return encoded

def decode(val, charset):
    charNum = 0
    decoded = ""
    for index in range(math.ceil(len(str(val)) / 2)):
        idy = str(val)[charNum] + str(val)[charNum + 1]
        charNum += 2
        tempDc = decoded
        decoded = tempDc + charset[1][int(idy) - 10]
    return decoded
while True:

    print()
    
    todo = input("type [e]ncode or [d]ecode or [q]uit : ")

    print()

    if todo == "q":
        break

    elif todo == "e":
        print("code : " + encode(input("encode : "), code))

    elif todo == "d":
        print("decoded : " + decode(input("decode : "), code))

    else:
        print("command not found")
Posted by: Guest on October-21-2021

Python Answers by Framework

Browse Popular Code Answers by Language