0
def afin(day,month,text):

    for i in range(len(text)):
        ascii = text[i] - 96
        y = (day * ascii) + month;
        while(y > 26):
            y -= 26

    sifrelenmiş_harf = y + 96
    sifrelimesaj += sifrelenmiş_harf



text = input("Enter Text:")
day = input("Birth Day:")
month = input("Birth Month:")
print(afin(day,month,text))

Hey, However, whenever I run this script, it comes up with this error:

    ascii = text[i] - 96

    TypeError: unsupported operand type(s) for -: 'str' and 'int'

How do i fix the mistake?

  • Does this answer your question? [TypeError: unsupported operand type(s) for -: 'str' and 'int'](https://stackoverflow.com/questions/2376464/typeerror-unsupported-operand-types-for-str-and-int) – Joseph Sible-Reinstate Monica May 03 '20 at 01:04

2 Answers2

0

I believe you are trying to get the ascii value of every element in a text. In order to do any numeric operation, you need to first convert the character to an integer value. One way is to use the below:

ord(text[i]) ### get the ascii character of your text

once you have this, then you could do the operations like:

 ascii = ord(text[i]) - 96

Hope this helps

Rishu Shrivastava
  • 3,745
  • 1
  • 20
  • 41
0

I think you are probably looking at something like this:

def afin(day,month,text):
x = ""
for i in range(len(text)):
    y = (int(day) * ord(text[i])) + int(month);
    y %= 26
    x += chr(y+ord('a'))
return x

text = input("Enter Text:")
day = input("Birth Day:")
month = input("Birth Month:")
print(afin(day,month,text))

A few changes i made here includes

  1. Instead of manually adding 96 use ord
  2. Instead of manually minus 96 use chr
  3. change day and month into integer so that you can compute y
  4. instead of while(y < 26): y-26 just use y %= 26

Take note your value will differ from most as your mod val is 26 but the algorithm should still be somewhat similar to above.

Jackson
  • 1,213
  • 1
  • 4
  • 14