Ir ao conteúdo
  • Cadastre-se

[Python] Dúvida na implementação do Vigenere Cipher modificado


Marcos Guimarães

Posts recomendados

Boa noite galera, alguém aqui que sabe python poderia me ajudar? Meu professor passou um trabalho em python e eu nunca mexi com python na minha vida, estou tendo um pouco de trabalho, já tentei quase tudo e não consigo resolver esse problema.

Isso é o que eu tenho que fazer:

Write a script in Python that is an implementation of a version of the Vigenere cipher for English text. Your script should distinguish lowercase and uppercase letters (i.e., the encryption key and the plaintext are allowed to be composed of lowercase and uppercase letters but the ciphertext should be uppercase). In addition to letters, there will be four other characters in the plain text: comma (26), dot (27), dash (28), underscore (29) changing the encryption function to be under mod 30. Your script should read from standard input and write to standard output. It should prompt the user for the encryption key of size k. The key is not allowed to be repeated as in the standard Vigenere cipher. Instead, we will follow a block cipher-based idea. Basically, the plaintext and ciphertext will have blocks of size k which is same as the key size. If the key length is shorter than the plaintext, the ciphertext of block size k of the previous block is concatenated to the key. Here is an example when the keyword is ”Carbondale” with k = 10:

Plaintext : SIU_CS-Department_is_the_best Key : CarbondaleUIHAQBBDPTUZ,MUOUCX Ciphertext: UIHAQBBDPTUZ,MUOUCXHTODQTPYUM

Esse é o meu código até agora (estou usando o terminal do ubuntu pra compilar):

text = []encr = []encr1 = []key = []answer = []i = 0key = raw_input("Type your key: ")text = raw_input("Type your message: ")#print(key)#print(text)text = text.lower()key = key.lower()#print(text)#print(key)key1 = list(key)#print(len(key1))text1 = list(text)#print(ord(key1[0]))var = 0a = len(key)b = len(text)if (len(text)%len(key) == 0):    c = 0;else:    c = len(text)%len(key)    for i in range(0,len(key)-c):        text1.append('!')while (len(key1) <= len(text1)):        for i in range(0,a):        num1 = ord(text1[i+var])%97        num2 = ord(key1[i+var])%97        num3 = num1+num2        #print(i)        if (num3 > 25):            encr.append(num3%25)        else:            encr.append(num3)        i + 1    #print(encr)                for i in range(0,a):        encr1.append(chr(encr[i+var]+97))        i + 1    #print(encr1)        for i in range(0,a):        key1.append(encr1[i+var])        i + 1    #print(key1)    var = var + a    #print(var)if(c==0):    #print(encr1)    result = ''.join(encr1)        print(result.upper())else:    d = len(key)-c        for i in range(0,d):        del encr1[-1]        i + 1    #print(encr1)    result = ''.join(encr1)        print(result.upper())

Preciso de ajuda pra verificar se os caracteres digitados pertencem ao alfabeto do exercício, também gostaria de saber se alguém tem alguma ideia do que eu posso fazer pra tratar os caracteres adicionais "," "." "/" "_" Eles não ficam em sequência na tabela ASCII, por isso estou com dificuldades. Alguém, por favor, poderia me ajudar?

Link para o comentário
Compartilhar em outros sites

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...