/*
*Copyright (c) 2014,烟台大学计算机学院
*All gight reserved.
*文件名称:temp.cpp
*作者:邵帅
*完成时间:2014年10月30日
*版本号:v1.0
*/
#include <cstdio>
using namespace std;
int main()
{
char ch;
while((ch=getchar())!='\n')
{
putchar(ch-4);
}
return 0;
}
M$pszi$y是一个已经加密的字符串,由程序可以得出,程序的作用是将每一个字符的ASCⅡ码的值减4从而输出新的字符。
运行结果:
那么,在解密前,需要将加密数字提前输入。输入4(回车)M$pszi$y(回车),然后输出……
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
char ch;
int n;
cin>>n;
getchar();
while((ch=getchar())!='\n')
{
putwchar(ch-n);
}
return 0;
}
这样,只有输入4后才能正确显示出加密的字符。
如果不知道N的值,那么列出所有可能的情况,输入M$pszi$y,多行输出中必然有一行是密码。
<span style="font-size:14px;">/*
*Copyright (c) 2014,烟台大学计算机学院
*All gight reserved.
*文件名称:temp.cpp
*作者:邵帅
*完成时间:2014年11月2日
*版本号:v1.0
*/
#include<iostream>
#include <cstdio>
using namespace std;
int main()
{
char ch;
int n;
while((ch=getchar())!='\n')
{
for (n=1;n<=9;n++)
{
putchar(ch-n);
cout<<" ";
if (n>8)
cout<<endl;
}
}
return 0;
}
</span>运行结果:
@ Mayuko
本文介绍了一个简单的字符加密与解密程序实现方法。通过ASCII码值的变化进行加密处理,并提供了几种不同的程序示例来演示如何根据已知或未知的偏移量解密字符串。
1005

被折叠的 条评论
为什么被折叠?



