Нужна помощь в создании этого шифратора - PullRequest
0 голосов
/ 28 февраля 2019

Привет, у меня есть этот шифр, который я собираюсь сделать на школьном уровне GCSE, и мне нужна помощь, потому что я не понимаю, что с ним не так в данный момент, я ожидаю, что всплывет окончательное число вместо зашифрованного скрипта, но я получил строкуошибка индекса как мне это исправить?

# This asks a user for an input of text integers etc
text = input('Enter A Word : ')
# Empty Value used to store the encrypted value
encrypt = ''
# Empty temp value replaced at every iteration of the wencryption process
temp = ''
# Empty temp value replaced at every iteration of the wencryption process
temp2 = ''

# key used to shift the letters
key = int(input('Enter your key (their will be more encryption) : '))

for i in range(0,len(text)):
    # Rearranges text in a caps switch
    if str.islower(text[i]):
        temp += str.upper(text[i])
    elif str.isupper(text[i]):
        temp += str.lower(text[i])
    else:
        temp += text[i]

for j in range(0, len(temp)):
    temp = str(ord(temp[j]))
    temp2 += temp + str(key)
    encrypt += temp2

print(encrypt)

Ответы [ 2 ]

0 голосов
/ 02 марта 2019

Спасибо, ребята, за поддержку;Я понял, как решить этот алгоритм шифрования.Ответ будет опубликован ниже (PS, очевидно, вы можете использовать это).Этот скрипт Python использует функции for и range для разделения строки на каждого отдельного символа, чтобы затем ее можно было переставить.

Сначала я делаю простой ключ cAPS (пока что не требуется), чтобы сделать свой шифратор защищенным.Затем я использую функцию ord для преобразования каждого символа в его эквивалент ascii, затем использую простую технику шифрования и запрашиваю простой целочисленный ключ (например, 3 [Цезарь] или 13 [ROT13]).Затем добавляется значение ascii и ключ, поэтому значение ascii изменяется соответственно.

Затем мы преобразовываем цифру ascii в символ, используя функцию chr, которая используется для преобразования значений ascii в chr.Когда мы это сделаем, мы используем конкатенацию, чтобы присоединить каждую букву к конечной переменной, чтобы потом отобразить ее на экране!

enter code here

text = input('Enter A Word : ') ##This asks a user for an input of text integers etc
encrypt = '' ##Empty Value used to store the encrypted value
temp = '' ##Empty temp value replaced at every iteration of the encryption process
temp2 =0 ##Empty temp value replaced at every iteration of the encryption process
temp_val=0
temp_char=''

key=int(input('Enter your key (their will be more encryption) : '))##key used to shift the letters

for i in range(0,len(text)):
    ##Rearranges text in a caps switch
    if str.islower(text[i])==True:
        temp=temp+str.upper(text[i])
    elif str.isupper(text[i])==True:
        temp=temp+str.lower(text[i])
    else:
        temp=temp+text[i]
for j in range(0,len(temp)):
    temp_val=0
    temp2=0
    temp_val=ord(temp[j])
    temp2=temp2+temp_val+key
    temp_char=temp_char+chr(temp2)
    encrypt=temp_char
print(encrypt)
print(temp)
print(temp2)
0 голосов
/ 28 февраля 2019

Я не совсем понял, что должно было произойти в temp=str(ord(temp[i])).

Этот код генерирует число:

text = input('Enter A Word : ') ##This asks a user for an input of text integers etc
encrypt = '' ##Empty Value used to store the encrypted value
temp = '' ##Empty temp value replaced at every iteration of the wencryption process
temp2 = '' ##Empty temp value replaced at every iteration of the wencryption process

key=int(input('Enter your key (their will be more encryption) : '))##key used to shift the letters


for i in range(0,len(text)):
    ##Rearranges text in a caps switch
    if str.islower(text[i])==True:
        temp=temp+str.upper(text[i])
    elif str.isupper(text[i])==True:
        temp=temp+str.lower(text[i])
    else:
        temp=temp+text[i]
for j in temp:
    temp=str(ord(j))
    temp2=temp2+temp+str(key)
    encrypt=encrypt+temp2
print(encrypt)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...