lundi 7 juin 2021

I am trying to create a encryption code using python. I am trying to use a return statement and a def function [closed]

I keep on getting the error statement "local variable 'answer' referenced before assignment" I am confused on the fix this. I want to be able to encryptionthingy('mason') and then have print(encryptionthingy('mason') return NGTWN. I am very new to coding and I am very confused on how to get help.

ultimate_key = 1618033988749894848204586834365638117720309179805762862135448622705260462818902449707207204189391137484754088075386891752126633862223536

best_key = str(ultimate_key)

alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z','A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']


answer = ""


def encryptionthingy(word):
    
    for n in range (0 , int(len(word))): 
    
        ogletter = word[n].upper()
    
        alpha_pos = (float(alphabet.index(ogletter)))
    
        encryption = (float(best_key[n]))
        
        new_encrypletter = (alpha_pos + encryption)
        
        if int(new_encrypletter) > 27:
            new_new_encrypletter = alphabet[(abs(int(new_encrypletter) - 28))]
        else:
            new_new_encrypletter = alphabet[int(new_encrypletter)]
        
        answer += new_new_encrypletter
        
    return answer

Aucun commentaire:

Enregistrer un commentaire