I tried to encrypt an affine cipher reading from text file. My .txt
files include two key: alpha
and beta
. Alpha
should be an odd number because gcd(alpha, 26)==1
and generate random key. Here is my code:
beta = rand() % 26;
but encryption doesn't work correctly. For example: the encrypted word "bahar"
, when encrypted, turns out in the "XWDWN"
word but it should be start "M"
not "X"
. Keys are alpha = 3
and beta = 9
but my code selected key (1, 22) alpha=1 beta=22
. Constantly alpha has been selected "1"
. Another encryption for example (1, 17)
.. etc.
这是加密的方式
putc(((toupper(p) - 'A')*alpha + beta) % 26 + 'A', cipher);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.