Python Forum
Cryptography Problem - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Cryptography Problem (/thread-1707.html)

Pages: 1 2 3


RE: Cryptography Problem - PYTHONEUR - Jan-22-2017

If someone here can explain what should i do ?

Im lost...


RE: Cryptography Problem - wavic - Jan-23-2017

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


RE: Cryptography Problem - PYTHONEUR - Jan-23-2017

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=" | ")
 

    
 



RE: Cryptography Problem - PYTHONEUR - Jan-23-2017

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

Why...


RE: Cryptography Problem - wavic - Jan-23-2017

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.


RE: Cryptography Problem - PYTHONEUR - Jan-24-2017

Shocked Ah ok, sorry i m not very good in English

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


RE: Cryptography Problem - PYTHONEUR - Jan-24-2017

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


RE: Cryptography Problem - wavic - Jan-24-2017

(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-an-Encryption-And-Decryption


RE: Cryptography Problem - PYTHONEUR - Jan-25-2017

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