-2

Im going to make a C++ program about Affine Cipher but i also want to encode the strings with numbers in it. I know for alphabet the formula is:

TO ENCODE: X=(a*x)+b mod 26

TO DECODE: Y=Z*(y-b) mod 26 "Z is the inverse of a"

But how can i imply this formula for numbers? I tried to Google it but i couldnt find anything about it.

NOTE:Excuse my grammar mistakes.

Snxby
  • 1

1 Answers1

1

You can simply extend your "alphabet", so you would perform calculations modulus 26 + 10 = 36. For instance, if you did encode 'A' to the value 0 and 'Z' to the value 25 then the digit '0' would become 26 and the digit '9' would become 35. You can of course also start with 0 and place the digits before the alphanumerical letters.

Kind of obvious, but the scheme would not be compatible with your earlier scheme; if you perform modulus calculations then changing the modulus will break previous calculations.

Maarten Bodewes
  • 92,551
  • 13
  • 161
  • 313
  • What if i apply affine cipher to the numbers seperatly ? I tried to use formula a*x+b mod 10 but it didnt worked. – Snxby May 20 '17 at 13:24