Python Forum

Full Version: Cryptography Problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
If someone here can explain what should i do ?

Im lost...
Keep each value of 'r' during iteration in a list for example then loop over the list and turn the each number into letter then prints them formated
So in the beginning i use : 

 r=  (A*(ord(c)-65)+ B)%26 

    print(r , end=" | " )
After I have the string bug

And what should i do for "chr" and "n" ?

So now i found not the letters i want, what should i do ?

Msg ="MATHS"
  
def num (caractere): 
    return ord (caractere)-65
  
def lettre (n):
    return  chr('65') + 'n'
      
for c in Msg :
    print (c,end="|")
print()
for c in Msg :
     print(num(c), end=" | ")
print ('\n\n', 'le message est sous forme de chiffres')
for c in Msg: 
    print ( '\n\n','Maintenant veuillez entrer deux chiffres pour créer votre cles ')
      
    # Finir Cle
     
    print ('\n\n', 'soit la fonction affine a*x + b qui va vous permettre de créer votre cles ')
     
A = 11
B = 7
  
  
for c in Msg:
    r= (A*(ord(c)-65)+ B)%26 + 65
    print(lettre(r),end=" | ")
 

    
 
Now the letters appears but they are strange : "An"

Why...
Well, 
for c in Msg:
    r=  (A*(ord(c)-65)+ B)%26 
    print(lettre(r), end= " | " )
evaluates for 'r' in this numbers [74, 72, 73, 71, 88]. When you substract 65 from each of them you get numbers between 9 and 23. The printable characters start from 32 which itself is space. See http://www.asciitable.com/ . These are not letters.
Shocked Ah ok, sorry i m not very good in English

so now it's ok, but how have spaces between lines ?
Someone know how to use the inverse of modulo on python ?

 
A = a**-1
B = A*a 
so what should i do after ?


 Now I have to create a decoder
(Jan-24-2017, 11:54 AM)PYTHONEUR Wrote: [ -> ]Shocked Ah ok, sorry i m not very good in English

so now it's ok, but how have spaces between lines ?

Print a new line - print(). Or add aditional '\n' at the end of the previous print().
As acording to decription you have to revers the (A*(ord(c)-65)+ B)%26

Look at this: https://python-forum.io/Thread-What-is-a...Decryption
Ok but after this :

"(a*(ord©-65)+ b)%26"
"62%)b +)56-)c(dro(*a("

I was thinking about reversing the affine function. Key(5;7)
a = 5, b = 7 12 = M
Imagine f(12) = 5(12) + 7 = 67
after this we search the rest of the division by :
67/26
we find r = 15 = P

So what should i do for reverse this
Pages: 1 2 3