c - 加密程序ascii问题

标签 c encryption

我正在为那些看过我之前帖子的人开发相同的加密程序。现在程序将接受字母,它显示了从 ascii 到字母的转换,但是有一个问题。在我对字母的值添加任何计算之前,它会打印得很好。例如,如果我输入 f,我得到 102。但是,当我尝试计算时,例如将 ascii 值乘以选定的素数,该值本身变得很大! 这是代码:

#include<stdio.h>
int main(){
int x,y,z;
int encrypt_number[] = {7507,55529,77933,142867,392263};
printf("\tCaleb's encryption machine\n");
printf("Please enter a letter to be encrypted:\n");
scanf("%[a-z]s",&x);
printf("Enter your encryption key number between one and five\n");
scanf("%d",&y);
if (y == 1)
y = encrypt_number[0];
else if ( y == 2 )
y = encrypt_number[1];
else if ( y == 3 )
y = encrypt_number[2];
else if ( y == 4 )
y = encrypt_number[3];
else if ( y == 5 )
y = encrypt_number[4];
else
printf("not a valid option\n");
z = x*y;
printf("Your encrypted value is: %d\n",z);
printf("\tdiagnosis of encryption:\n");
printf("Letter was: %c\n",x);
printf("value in ascii was: %d\n");
}

在上面的例子中,f 变成了 264241254!希望这只是一个简单的错误?

最佳答案

打印

printf("value in ascii was: %d\n"); 

您只提供格式说明符 %d 但不传递您想要 print. 的参数。

关于c - 加密程序ascii问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23051848/

相关文章:

无法打印在循环中递增的变量值

SQL Server - 加密数据库表列中的数据

php - 如何使用带有 GET 方法的 Laravel 表单在 URL 中以加密格式传递 GET 参数?

node.js - NPM - ActiveDirectory 模块身份验证

c++ - 打印第 n 个斐波那契数 [最多 1000 位]

c - MicroChip dsPic33,UART RX 中断未被调用

c - 结构体指针转换及其内存分配

ios - 使用 NSInputStream 就地 NSMutableData 加密

java - GNU 加密货币 : JCE cannot authenticate the provider GNU-CRYPTO

c++ - 为什么 gets() 需要更多字符