Ⅰ c语言设计一个简单的加密解密程序
C语言设计一个简单的加密解密程序如下:
加密程序代码:
#include<stdio.h>
main()
{
char c,filename[20];
FILE *fp1,*fp2;
printf("请输入待加密的文件名:\n");
scanf("%s",filename);
fp1=fopen(filename,"r");
fp2=fopen("miwen.txt","w");
do
{
c=fgetc(fp1);
if(c>=32&&c<=126)
{
c=c-32;
c=126-c;
}
if(c!=-1)
fprintf(fp2,"%c",c);
}
while(c!=-1);
}
解密程序代码:
#include<stdio.h>
#include<string.h>
main()
{
char c,filename[20];
char yanzhengma[20];
FILE *fp1,*fp2;
printf("请输入待解密文件名:\n");
scanf("%s",filename);
printf("请输入验证码:\n");
scanf("%s",yanzhengma);
if(strcmp(yanzhengma,"shan")==0)
{
fp1=fopen(filename,"r");
fp2=fopen("yuanwen.txt","w");
do
{
c=fgetc(fp1);
if(c>=32&&c<=126)
{
c=126-c;
c=32+c;
}
if(c!=-1)
fprintf(fp2,"%c",c);
}
while(c!=-1);
}
else
{
printf("验证码错误!请重新输入:\n");
scanf("%s",filename);
}
}
Ⅱ C语言(文件的移位与加密解密)
这道题,并不难,只是楼主,没有说清,是就字母移位吗?
但是看你的例子,有不全是。
程序如下:
#include <stdio.h>
#include <stdlib.h>
FILE *source;//源文件
FILE *destination;//目标文件
int key;//密钥
char file[100];//文件名
void encryption()//加密
{
char ch;
printf("请输入要加密的文件名\n");
scanf("%s",file);
if((source=fopen(file,"r"))==NULL)
{
printf("无法打开文件!\n");
exit(0);
}
printf("请输入加密后的文件名\n");
scanf("%s",file);
if((destination=fopen(file,"w"))==NULL)
{
printf("无法创建文件!\n");
exit(0);
}
printf("请输入密钥\n");
scanf("%d",&key);
ch=fgetc(source);
while(ch!=EOF)
{
if(ch=='\n')
{
fputc(ch,destination);
ch=fgetc(source);
continue;
}
ch+=key;
fputc(ch,destination);
ch=fgetc(source);
}
fclose(source);
fclose(destination);
}
void decrypt()//解密
{
char ch;
printf("请输入要解密的文件名\n");
scanf("%s",file);
if((source=fopen(file,"r"))==NULL)
{
printf("无法打开文件!\n");
exit(0);
}
printf("请输入加密后的文件名\n");
scanf("%s",file);
if((destination=fopen(file,"w"))==NULL)
{
printf("无法创建文件!\n");
exit(0);
}
printf("请输入密钥\n");
scanf("%d",&key);
ch=fgetc(source);
while(ch!=EOF)
{
if(ch=='\n')
{
fputc(ch,destination);
ch=fgetc(source);
continue;
}
ch-=key;
fputc(ch,destination);
ch=fgetc(source);
}
fclose(source);
fclose(destination);
}
int main()//主函数提供菜单
{
int choice=0;
printf("******************\n");
printf("1 文件加密\n");
printf("2 文件解密\n");
printf("3 退出\n");
printf("******************\n");
printf("请输入1 2 3选择操作\n");
scanf("%d",&choice);
switch(choice)
{
case 1:encryption();break;
case 2:decrypt();break;
case 3:break;
}
return 0;
}
Ⅲ C语言编程: 文件移位加密与解密。
直接对字符串按字符加减密钥的位数就可以了。
#include
<iostream.h>
#define
MAX
1000
//加密
char
*
Encryption(char
*E,int
Key)
{
for(int
i=0;*(E+i);i++)
{
*(E+i)
+=
Key;
if(*(E+i)>'z')
*(E+i)
-=
('z'-'a')+1;
}
return
E;
}
//解密
char
*
Decryption(char
*E,int
Key)
{
for(int
i=0;*(E+i);i++)
{
*(E+i)
-=
Key;
if(*(E+i)<'a')
*(E+i)
+=
('z'-'a')+1;
}
return
E;
}
void
main()
{
char
a[MAX];
int
key;
cout<<"输入字符串:"<<endl;
cin
>>
a;
cout<<"输入密钥:"<<endl;
cin
>>key;
cout<<"加密输出:"<<Encryption(a,key)<<endl;
cout<<"解密输出:"<<Decryption(a,key)<<endl;
}
Ⅳ 跪求c语言编程问题 文件移位加密与解密 急!
我自己用C#做了一下这功能,注释都写上了,希望能帮上你忙 ~ ~using System;
using System.Collections.Generic;
using System.Text;namespace myHomeworkTest30
{
class Program
{
static void Main(string[] args)
{
Emp emp = new Emp();//定义一个对象.自动调用其构造方法,接收字符串并转化为字符数组
int len=emp.show();//调用实现加密字符串的方法,并返回字符数组的长度
for (int i = 0; i < len-1; i++)
{
Console.Write(emp[i]);//通过索引器进行输出
}
Console.ReadLine();
}
}
public class Emp
{
public string str = "";//接收字符串
public char[] arr;//字符数组来用存放把字符串转后成字符
public char first;//加密后的字符串中的第一个字符
public Emp()
{
Console.WriteLine("请输入一个要加密的字符串:");
str = Console.ReadLine();//接收
arr=str.ToCharArray();//字符串.ToCharArray()把字符串转化为字符数组
}
public int show()//实现加密的方法
{
first=arr[arr.Length - 1];//把原字符数组中的最后一个字符拿出来作为加密后的第一个字符
Console.WriteLine("加密后的字符串为:");
Console.Write(first);//输出加密后的第一个字符
for (int i = 0; i < arr.Length; i++)
{
arr[i] = (char)(arr[i] + 3);//对于其它的字符进行加密,+3
}
return arr.Length;//返回字符数组的长度
}
//定义一个索引器
public char this[int index]
{
get
{
return arr[index];
}
set
{
arr[index] = value;
}
}
}
}
Ⅳ 利用C语言实现移位加密和解密算法
呵呵
这两天刚编了一个
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void main()
{
char a[500];
gets(a);
int n,i;
n = strlen(a);
for(i=0;i<n;i++)
if(a[i]=='y')
a[i]='a';
else if(a[i]=='z')
a[i]='b';
else if (isalpha(a[i]))
a[i] += 2;
printf("%s",a );
}
这个是往后推2的解密。
g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle.
解密试试吧~~
加密的话
改动三个地方就行 自己试试吧 哈哈
Ⅵ c语言 文件移位加密与解密
您说的这个方法,我没有操作过。 给文件加密,我使用的是超级加密3000. 超级加密3000采用国际上成熟的加密算法和安全快速的加密方法,可以有效保障数据安全! 具体操作方法: 1 下载安装超级加密3000。
Ⅶ c语言问题 密码破解功能,对输入的字符进行移位操作,输入字符必须为2
#include<stdio.h>
#include<stdlib.h>
int main(int argc,char *argv[])
{
char c;
char f[]="t.txt";
FILE *in;
do
{
printf("请输入一个要加密的英文字母:");
scanf("%c",&c);
if(c>='a' && c<='z')
{
c+=2;
c='a'+(c-'a')%26;
break;
}
else if(c>='A' && c<='Z')
{
c+=36;
c='a'+(c-'a')%26;
break;
}
else
{
printf("你输入的不是英文字母,请重新输入。\n");
getchar();
}
}while(1);
in=fopen(f,"w");
fprintf(in,"%c",c);
fflush(in);
fclose(in);
printf("已保存。\n");
system("PAUSE");
return 0;
}
Ⅷ 用C语言编写文件移位加密与解密程序,如加密:设原文为abcdef,密钥为5,则有abcdef每个字母按字母表向后
您说的这个方法,我没有操作过。
给文件加密,我使用的是超级加密3000.
超级加密3000采用国际上成熟的加密算法和安全快速的加密方法,可以有效保障数据安全!
具体操作方法:
1 下载安装超级加密3000。
2 然后在需要加密的文件上单击鼠标右键选择加密。
3 在弹出的文件加密窗口中设置文件加密密码就OK了。
Ⅸ 求移位密码(凯撒密码)在c#上实现的详细代码
忘了说解密了,解密过程完全可以使用上面的代码,只要把key的值改成26-key就行了。比如,加密的密钥是3,那么解密密钥就是23,这样就可以使用同一段代码。至于为什么+23和-3的效果一样,还请翻阅数论有关剩余类环的知识。
Ⅹ C语言密码移位问题
明文移动k位之后,如果超出了字母z,如:z字母向右移动16位,已经超出了范围,就需要经过处理
chare(charm,intk)
{
m=m+k;
if(m>90)m=k-90+65;//这里涉及到按键码问题,每个键盘都有一个asc2码,Z=90,A=65
returnm;
}