Python Forum
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cryptography Problem
#11
Why you open a new topic?
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#12
(Jan-22-2017, 10:36 AM)PYTHONEUR Wrote: Hi Wavic

Yes i know i have ubuntu in linux but my ubuntu/linux system are break like python :(

So no Python scripts

Thanks for the explanation I have a little better advanced, but now I encounter another problem how to convert correctly into letter?

In the example below I use ord to convert to a letter


Msg ="MATHS"
 
def num (caractere): 
    return ord (caractere)-65
 
def lettre (n):
     return  n + ord(65)
   
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(r, end=" | " )
for c in Msg:    
    print(lettre(r), end=" | ")

Thanks for the explanation I have a little better advanced, but now I encounter another problem how to convert correctly into letter?

In the example below I use ord to convert to a letter


Msg ="MATHS"
 
def num (caractere): 
    return ord (caractere)-65
 
def lettre (n):
     return  n + ord(65)
   
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(r, end=" | " )
for c in Msg:    
    print(lettre(r), end=" | ")

Now i have a new prob :

TypeError: ord() expected string of length 1, but int found

Forget all that I have said now, why i have that valor :

"nA"

Hi Wavic Yes i know i have ubuntu in linux but my ubuntu/linux system are break like python :(


So no Python scripts

Thanks for the explanation I have a little better advanced, but now I encounter another problem how to convert correctly into letter?

I have that valor : "nA"


Now i have a new prob : TypeError: ord() expected string of length 1, but int found

Forget all that I have said now, why i have that valor : "nA"

Hi Wavic Yes i know i have ubuntu in linux but my ubuntu/linux system are break like python :( So no Python scripts Thanks for the explanation I have a little better advanced, but now I encounter another problem how to convert correctly into letter? I have that valor : "nA"

Sorry for the spam :(

i can't delete all this...



Ok but where i can see the letters :( : 

Msg ="MATHS"
 
def num (caractere): 
    return ord (caractere)-65
 
def lettre (n):
    return  chr(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(r , end=" | " )

for c in Msg :
    R = r-65
    print(lettre(R), end= " | " )
    
   

   

(Jan-22-2017, 10:36 AM)PYTHONEUR Wrote: Hi Wavic Yes i know i have ubuntu in linux but my ubuntu/linux system are break like python :( So no Python scripts
Thanks for the explanation I have a little better advanced, but now I encounter another problem how to convert correctly into letter? In the example below I use ord to convert to a letter
Msg ="MATHS"   def num (caractere):      return ord (caractere)-65   def lettre (n):      return  n + ord(65)     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(r, end=" | " ) for c in Msg:         print(lettre(r), end=" | ") 

Thanks for the explanation I have a little better advanced, but now I encounter another problem how to convert correctly into letter? In the example below I use ord to convert to a letter
Msg ="MATHS"   def num (caractere):      return ord (caractere)-65   def lettre (n):      return  n + ord(65)     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(r, end=" | " ) for c in Msg:         print(lettre(r), end=" | ") 

Now i have a new prob : TypeError: ord() expected string of length 1, but int found
Forget all that I have said now, why i have that valor : "nA"
Hi Wavic Yes i know i have ubuntu in linux but my ubuntu/linux system are break like python :( So no Python scripts Thanks for the explanation I have a little better advanced, but now I encounter another problem how to convert correctly into letter? I have that valor : "nA"

Now i have a new prob : TypeError: ord() expected string of length 1, but int found
Forget all that I have said now, why i have that valor : "nA"
Hi Wavic Yes i know i have ubuntu in linux but my ubuntu/linux system are break like python :( So no Python scripts Thanks for the explanation I have a little better advanced, but now I encounter another problem how to convert correctly into letter? I have that valor : "nA"
Sorry for the spam :( i can't delete all this... Ok but where i can see the letters :( : 
Msg ="MATHS"   def num (caractere):      return ord (caractere)-65   def lettre (n):     return  chr(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(r , end=" | " ) for c in Msg :     R = r-65     print(lettre(R), end= " | " )             
Reply
#13
There is a lot of bugs, it's the new

Here the new code, but why i can't see the letters

i use 
[return  chr(int(65)) + n/python]


[python]Msg ="MATHS"
 
def num (caractere): 
    return ord (caractere)-65
 
def lettre (n):
    return  chr(int(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 
    print(r , end=" | " )

for c in Msg :

    print(lettre(r), end= " | " )
    
   

   

(Jan-22-2017, 12:09 PM)PYTHONEUR Wrote: There is a lot of bugs, it's the new
Here the new code, but why i can't see the letters i use
[return  chr(int(65)) + n/python] [python]Msg ="MATHS"   def num (caractere):      return ord (caractere)-65   def lettre (n):     return  chr(int(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      print(r , end=" | " ) for c in Msg :     print(lettre(r), end= " | " )             

Delete the first line of the code
Reply
#14
Output:
victor@jerry:~$ python3 test.py M|A|T|H|S| 12 | 0 | 19 | 7 | 18 |  le message est sous forme de chiffres  Maintenant veuillez entrer deux chiffres pour créer votre cles  soit la fonction affine a*x + b qui va vous permettre de créer votre cles  Maintenant veuillez entrer deux chiffres pour créer votre cles  soit la fonction affine a*x + b qui va vous permettre de créer votre cles  Maintenant veuillez entrer deux chiffres pour créer votre cles  soit la fonction affine a*x + b qui va vous permettre de créer votre cles  Maintenant veuillez entrer deux chiffres pour créer votre cles  soit la fonction affine a*x + b qui va vous permettre de créer votre cles  Maintenant veuillez entrer deux chiffres pour créer votre cles  soit la fonction affine a*x + b qui va vous permettre de créer votre cles 74 | 72 | 73 | 71 | 88 |  |  |  |  |  |
This is what I get as output. Which letters you can't see? Between | | | | | |? This is because the scripts returns a nonprintable characters.
[Image: dytd6b]

Also, the 'r' will contain the last value from the previous for loop
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#15
((Please don't delet this post Delet the others))

Sorry for the spam :(

Here the code you can test it in this site : http://www.pythontutor.com/visualize.html#mode=display

Always the pro with chr and ord










Msg ="MATHS"
 
def num (caractere): 
    return ord (caractere)-65
 
def lettre (n):
    return  chr(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 
    print(r , end=" | " )
    
for c in Msg:
    print(lettre(r), end= " | " )

   

   
 
   
Reply
#16
Merged your 3 threads together. And deleted the other duplicate threads. Please dont make a new thread every time your code changes slightly. Also dont remove post content and replace it with nothing. Please refer to our help documents for our rules.
Recommended Tutorials:
Reply
#17
Guys i have this new code

Why i can't see the letters, if think it's again chr in line 5

[/Msg ="MATHS"
 
def num (caractere): 
    return ord (caractere)-65
 
def lettre (n):
    return  chr(r)
     
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 
    print(r , end=" | " )
    
for c in Msg:
    print(lettre(r), end= " | " )

   

   
   

   

Guys i have this new code Why i can't see the letters, if think it's again chr in line 5
[/Msg ="MATHS"   def num (caractere):      return ord (caractere)-65   def lettre (n):     return  chr(r)       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      print(r , end=" | " )      for c in Msg:     print(lettre(r), end= " | " )                
Reply
#18
As I said, 'r' holds the last value from the previous for loop. This one:

for c in Msg:
    r=  (A*(ord(c)-65)+ B)%26 
    print(r , end=" | " )
In the next wor loop 'r' will contain one value each iteration. If it is nonpritable character, as it seems to be, you would't see anything in the output
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#19
Quote:Larz60+ Wrote: es i use python On-line, i don't have python because i have Ubuntu

No I did not write this
Reply
#20
Ok, but what should i do for "r" ?

int ? int® but i didn't work

str i don't know...

So i change it into this : Still the same problem  Sad

or c in Msg:
    r=  (A*(ord(c)-65)+ B)%26 
    print(lettre(r), end= " | " )
 

   
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple Cryptography Capture the Flag DrEastwood 12 11,550 Oct-12-2016, 11:40 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020