英文大寫加密
如果要求不高的話,簡單點用移位演算法就好了,每個字母加N。比如a->c, b->d, ... , z->b.
N就是你的密鑰,這里是2
❷ 12.編寫一個程序,輸入一個字元串,將其中所以的大寫英文字母+3,小寫字母-3。然後再輸出加密後的
#include<stdio.h>
char*Change(chars[]){
inti;
for(i=0;s[i];++i){
if(s[i]>='a'&&s[i]<='z')
s[i]=(26+(s[i]-'a'-3))%26+'a';
if(s[i]>='A'&&s[i]<='Z')
s[i]=(26+(s[i]-'A'+3))%26+'A';
}
returns;
}
char*Change2(chars[]){
inti;
for(i=0;s[i];++i){
if(s[i]>='a'&&s[i]<='z')
s[i]=(26+(s[i]-'a'+3))%26+'a';
if(s[i]>='A'&&s[i]<='Z')
s[i]=(26+(s[i]-'A'-3))%26+'A';
}
returns;
}
intmain(){
chara[]="dsereaiklfiwieik",b[]="slASSFGGHHJHKKIUUYUYYHHNJKK";
printf("轉換前:%s ",a);
printf("轉換後:%s ",Change(a));
printf("恢復後:%s ",Change2(a));
printf("轉換前:%s ",b);
printf("轉換後:%s ",Change(b));
printf("恢復後:%s ",Change2(b));
return0;
}
#include<stdio.h>
#include<ctype.h>
intmain()
{inti;
chars[200];
gets(s);
for(i=0;s[i];i++)
if(isalpha(s[i]))
{s[i]+=3;
if(s[i]%0x20>26)s[i]-=26;
}
puts(s);
return0;
}
❹ 純數字的加密成4位英文字母的方式(一般用於網站)
做回好人,回答你吧。直接看代碼:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class jiami {
public static void main(String[] args) {
String source=null,target=null;
try {
FileInputStream fileread = new FileInputStream(new File("D:/a.txt"));//路徑自己改
int length = fileread.available();
byte[] buffer = new byte[length];
fileread.read(buffer);
source = new String(buffer);//讀取
fileread.close();
} catch (Exception e) {
e.printStackTrace();
}
if(source==null)
System.out.println("a.txt為空");
else{
System.out.println(source);
target=zhuanhuan(source);
System.out.println(target);
try {
FileOutputStream out = new FileOutputStream(new File("D:/b.txt"));
out.write(target.getBytes());//寫入
out.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static String zhuanhuan(String s){
char []array = s.toCharArray();
for(int i=0;i<array.length;i++){
//字母轉換這里用ASCII碼來,方便快捷,大寫字母是65-90,小寫字母是97-122
int j = (int)array[i];
if(j>=65&&j<=90){
if(j==90)
j=65;
else j=j+1;
array[i]=(char)j;
}
if(j>=97&&j<=122){
if(j==122)
j=97;
else j=j+1;
array[i]=(char)j;
}
//數字轉換的話由於數字比較少,就直接轉換了,不用ASCII碼了
if(array[i]=='1')
array[i]='0';
else if(array[i]=='2')
array[i]='9';
else if(array[i]=='3')
array[i]='8';
else if(array[i]=='4')
array[i]='7';
else if(array[i]=='5')
array[i]='6';
else if(array[i]=='6')
array[i]='5';
else if(array[i]=='7')
array[i]='4';
else if(array[i]=='8')
array[i]='3';
else if(array[i]=='9')
array[i]='2';
else if(array[i]=='0')
array[i]='1';
}
return new String(array);
}
}
純手打。不採納對不起觀眾啊!!!
❺ 輸入一個字元串,將其進行加密,加密的方式是每個大寫英文字母用它後面的字母代替,即』A』變成』B』
#include<stdio.h>
int main() {
char s[100];
int i=0;
gets(s);
for(; s[i]!='\0'; i++) {
if(s[i]>='A' && s[i]<='Z')
printf("%c",s[i]=='Z'?'A':s[i]+1);
else printf("%c",s[i]);
}
}
❻ c語言對大寫英文字母加密
#include <stdio.h>
#include <string.h>
int main()
{
char passwd[100],encrypted[100];
int i,j,k,t,move;
while(1)
{
printf("Enter message to be encrypted:");
gets(passwd);
move=3;
for(i=0; i<strlen(passwd); i++)
{
if(passwd[i] >= 'A' && passwd[i] <= 'Z')
{
passwd[i] = ((passwd[i]-'A')+move)%26+'A';
} else if(passwd[i] >= 'a' && passwd[i] <= 'z')
{
passwd[i] = ((passwd[i]-'a')+move)%26+'a';
}
}
printf("%s",passwd);
printf("\n");
}
return 0;
}
這道題實際上就是C語言版的凱撒加密(字母往後面移動1-25之間的任意一位數)
❼ 將26個英文大寫字母依次用整數0,1,2...25代表。某加密程序如下:設某個字母用
請詳細補充題目!
中途邏輯性需要加強!
❽ 文件的加密. 使用「二戰」時簡單的加密演算法,即將英文的大寫字母或小寫字母循
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#defineMAX_FILE_NAME128
#defineMAX_STRING_SIZE256
voidencrypt(void);
voiddecode(void);
voipper(void);
voidlower(void);
voidfix(void);
intmain(intargc,char**argv)
{
intcommand=1;
while(command!=0)
{
printf("%-16s%-16s%-16s%-16s%-16s%-16s ","1.encrypt","2.decode","3.toupper","4.tolower","5.autofix","0.exit");
printf("entercommond'snumber:");
scanf("%d",&command);
switch(command)
{
case1:encrypt();break;
case2:decode();break;
case3:upper();break;
case4:lower();break;
case5:fix();break;
case0:break;
}
}
return0;
}
voidencrypt(void)
{
charsource[MAX_FILE_NAME];
chardestination[MAX_FILE_NAME];
printf("enterthefile'spathyouwanttoencrypt:");
scanf("%s",source);
printf(":");
scanf("%s",destination);
FILE*input=fopen(source,"r");
if(input==NULL)
{
printf("openfilefail ");
system("pause");
exit(1);
}
FILE*output=fopen(destination,"w");
if(output==NULL)
{
printf("createfilefail ");
system("pause");
exit(1);
}
intinch=fgetc(input);
while(!feof(input))
{
if(inch>='a')
fputc((char)('a'+(inch+4)%'a'),output);
else
fputc((char)('A'+(inch+4)%'A'),output);
inch=fgetc(input);
}
fclose(input);
fclose(output);
printf("complete ");
}
voiddecode(void)
{
charsource[MAX_FILE_NAME];
chardestination[MAX_FILE_NAME];
printf("enterthefile'spathyouwanttoencrypt:");
scanf("%s",source);
printf(":");
scanf("%s",destination);
FILE*input=fopen(source,"r");
if(input==NULL)
{
printf("openfilefail ");
system("pause");
exit(1);
}
FILE*output=fopen(destination,"w");
if(output==NULL)
{
printf("createfilefail ");
system("pause");
exit(1);
}
intinch=fgetc(input);
while(!feof(input))
{
if(inch>='a')
fputc((char)('a'+(inch+22)%'a'),output);
else
fputc((char)('A'+(inch+22)%'A'),output);
inch=fgetc(input);
}
fclose(input);
fclose(output);
printf("complete ");
}
voipper(void)
{
charinput[MAX_STRING_SIZE];
printf("inputasentence:");
scanf("%s",input);
charmode;
fflush(stdin);
printf("?(y/n):");
scanf("%c",&mode);
if(mode=='y')
printf("%s ",strupr(input));
else
{
char*temp=strlwr(input);
intlength=strlen(temp);
intj=length-1;
while(j>=0)
{
if(temp[j]=='.')
if(j+1<length)
if(temp[j+1]>='a')
temp[j+1]-=32;
j--;
}
printf("%s ",temp);
}
}
voidlower(void)
{
charinput[MAX_STRING_SIZE];
printf("inputasentence:");
scanf("%s",input);
char*temp=strlwr(input);
intlength=strlen(temp);
intj=length-1;
while(j>=0)
{
if(temp[j]=='.')
if(j+1<length)
if(temp[j+1]>='a')
temp[j+1]-=32;
j--;
}
if(length!=0)
if(temp[0]>='a')
temp[0]-=32;
printf("%s ",temp);
}
voidfix(void)
{
charinput[MAX_STRING_SIZE];
charoutput[MAX_STRING_SIZE];
printf("inputasentence:");
fflush(stdin);
gets(input);
intlength=strlen(input);
if(input[length-1]!='.')
input[length]='.',length++;
intcurrent=0,patt=0;
if(length)
output[current++]=toupper(input[patt++]);
while(patt<length)
{
if(input[patt]==','||input[patt]=='.')
{
intmode=0;
if(input[patt]=='.')
mode=1;
output[current++]=input[patt++];
output[current++]='';
while(patt<length&&(input[patt]==''||input[patt]==' '))
patt++;
if(patt<length&&mode)
output[current++]=toupper(input[patt++]);
}
elseif(input[patt]==''||input[patt]==' ')
{
output[current++]='';
while(patt<length&&(input[patt]==''||input[patt]==' '))
patt++;
}
else
output[current++]=input[patt++];
}
printf("%s ",output);
}
❾ 從鍵盤上輸入一個字元串存放在一個字元數組中,按以下規則加密:所有的大寫英文字母加3,小寫英文字母減
int main()
{
char str1[50],str2[50];
printf("請輸入字元串:|n");
gets(str1);
for(int i=0;str1[1]='\0';i++)
{
if(str1[i]>='a'&&str1[i]<='z')
str1[i]=str1[i]-4;
if(str1[i]>='A'&&str1[i]<='Z')
str1[i]=str1[i]+3;
str2[i]=str1[i];
}
printf("原字元串為:");
puts(str1);
printf("加密後字元串為:");
puts(str2);
return 0;
}