加密文本 有人可以告诉我如何做到这一点
encrypt text Could someone please show me how to do this?
我编写了一个程序,用于读取和打印用户选择的文本文件。我现在希望程序加密文件中的文本,并且用户能够选择字母移位。有人可以告诉我如何做到这一点吗?这是我到目前为止所拥有的:
#include <stdio.h>
int main(void) {
FILE *file_in;
char filename[20];
char ch;
int shift;
// file_in is the name given to the stream. filename will be the file that the user chooses. ch is the characters in the file.
printf("What file do you want to open?: ");
gets(filename);
file_in=fopen(filename, "r");
//ask the user to enter the name of a file
if(file_in==NULL)
printf("Error! File did not open.n");
//print message if the file can not be found
while((ch=fgetc(file_in)) != EOF)
putchar(ch);
//prints the results on the screen and shows the end of the file
fclose(file_in);
//closes stream
}`enter code here`
对于简单的字母移位,将移位存储为char
,并像从用户输入中读取文件名一样读取它。将putchar(ch);
替换为用于加密的putchar(ch+shift);
,将ch-shift
替换为解密或 vv。 如果总和大于char
的最大值,ch+shift
将静默溢出,从而保证每个字母ch
只有一个"加密"的对应者。
相关文章:
- 这是什么类型的C++语法,我应该采取什么步骤来理解这一点
- 我无法理解这一点,有人可以帮我解释一下吗?
- 结构本身就包含在内.如何理解这一点?
- 只需要知道我在c ++中打印模式的方式是否有效,或者有另一种方法可以有效地做到这一点
- 我可以直接为指针分配地址吗?如果是,如何做到这一点
- 请证明这一点的合理性 C++.
- 为什么要按值传递string_view?为什么Visual Studio不能优化这一点?
- [expr.unary.op]/9 似乎暗示"运算符!()' 不能应用于下面的类型 A.但编译器不同意这一点
- 为什么我有一个无限循环,我如何以不同的方式做到这一点
- 我想使用 CMake 生成和编译 Visual Studio projet,我需要从构建中排除单元测试文件。有没有办法做到这一点?
- 所有版本的 GCC 都与默认成员初始值设定项作斗争,该初始值设定项捕获了这一点,并结合了继承的构造函数
- 如果有条件使用String.length()的条件,为什么不一致地评估这一点
- 对随机序列进行降采样会降低随机性吗?有没有原理/定理来证明这一点?
- 在C++有没有更好的方法可以做到这一点?检查哪些数字满足条件 [A*B*C = A! + B! + C!]
- 4.5年应该是4年零178年,我如何在C 中做到这一点
- 为什么添加constexpr使VS2013拒绝这一点
- 如何在GTEST中否定匹配者断言或期望这一点
- 循环工作时如何做到这一点?
- 如何做到这一点:Objet.getsObject().setssObject()
- 为什么我在使用 Qt creator 用 C 编译代码时出错,但可以使用 make 文件轻松做到这一点