Posts: 2,953
Threads: 48
Joined: Sep 2016
Why you open a new topic?
Posts: 18
Threads: 2
Joined: Jan 2017
(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= " | " )
Posts: 18
Threads: 2
Joined: Jan 2017
Jan-22-2017, 12:09 PM
(This post was last modified: Jan-22-2017, 12:22 PM by PYTHONEUR.)
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
Posts: 2,953
Threads: 48
Joined: Sep 2016
Jan-22-2017, 12:34 PM
(This post was last modified: Jan-22-2017, 12:57 PM by wavic.)
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
Posts: 18
Threads: 2
Joined: Jan 2017
Jan-22-2017, 12:42 PM
(This post was last modified: Jan-22-2017, 12:49 PM by PYTHONEUR.)
((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= " | " )
Posts: 5,151
Threads: 396
Joined: Sep 2016
Jan-22-2017, 01:05 PM
(This post was last modified: Jan-22-2017, 01:05 PM by metulburr.)
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:
Posts: 18
Threads: 2
Joined: Jan 2017
Jan-22-2017, 01:19 PM
(This post was last modified: Jan-22-2017, 01:25 PM by metulburr.)
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= " | " )
Posts: 2,953
Threads: 48
Joined: Sep 2016
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
Posts: 12,043
Threads: 487
Joined: Sep 2016
Quote:Larz60+ Wrote: es i use python On-line, i don't have python because i have Ubuntu
No I did not write this
Posts: 18
Threads: 2
Joined: Jan 2017
Jan-22-2017, 03:25 PM
(This post was last modified: Jan-22-2017, 03:43 PM by PYTHONEUR.)
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
or c in Msg:
r= (A*(ord(c)-65)+ B)%26
print(lettre(r), end= " | " )
|