Search code examples
pythonpassword-encryption

Trying to add elements to list but getting out of range errors


import re 

sifrelenmisdizi = []
kelimeler = []
bulunankelimeler = []
input = input("Lütfen Şifrelenmiş Veriyi giriniz : ")
def sifrecoz(message): #im cracking password here
    encrypted = ""
    for i in range(25):
        for char in message:
            value = ord(char) + 1
            valuex = value % 123
            if (valuex <= 0):
                valuex = 97
                encrypted += chr(valuex)
            elif (valuex == 33):
                encrypted += chr(32)
            else:
                encrypted += chr(valuex)

        message = encrypted
        sifrelenmisdizi.append(encrypted)
        encrypted = ""

def kelime_getir(dosya_adi): # here im taking words on "kelimeler.txt" 
    with open(dosya_adi, 'r', encoding='utf-8') as input_file:
        dosya_icerigi = input_file.read()
        kelime_listesi = dosya_icerigi.split()
        index = 0
        while index <= 1164053:
            kelimeler.append(kelime_listesi[index]) #here im taking that issue
            index += 1
    return kelimeler

sifrecoz(input) 
kelime_getir("kelimeler.txt") 
for i in range(len(kelimeler)):  
    for j in range(len(sifrelenmisdizi)): 
        x = re.split("\s", sifrelenmisdizi[j]) 
        for k in range(len(x)):
            if (kelimeler[i] == x[k]): 
                bulunankelimeler.append(kelimeler[i])
print("Kırılmış şifreniz : ",bulunankelimeler)

# selam daktilo dalga = ugnco eblujmp ebmhb

Here I am coding a password cracking program with Caesar decryption of encrypted data and compare with "kelimeler" list.

I'm trying to add words to "kelimeler" list but I'm taking out of range error.

This is my word list:
[URL=https://dosya.co/31174l7qq8zh/kelimeler.txt.html]kelimeler.txt - 16.9 MB[/URL]


Solution

  • It appears that the function kelime_getir is expected to return a list of all the words in the file (which has one word per line).

    Therefore:

    def kelime_getir(dosya_adi):
      with open(dosya_adi, encoding='utf-8') as txt:
        return list(map(str.strip, txt))
    

    ...is all you need