做回好人,回答你吧。直接看代码:
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;iarray.length;i++){
//字母转换这里用ASCII码来,方便快捷,大写字母是65-90,小写字母是97-122
int j = (int)array[i];
if(j=65j=90){
if(j==90)
j=65;
else j=j+1;
array[i]=(char)j;
}
if(j=97j=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);
}
}
纯手打。不采纳对不起观众啊!!!
#include
#include
void replace(char *src, int n)
{
char *s = src;
n = n % 26;
while(*s != 0)
{
*s = *s + n;
if(*s 'Z') *s -= 26;
s++;
}
}
void disorder(char *s, char *key)
{
int len = 0 , i = 0;
char *tmp;
while(s[len++] != 0);
tmp = (char*)malloc(sizeof(char) * (len));
while(i len) tmp[i] = s[i++];
for(i = 0; i len - 1; i++)
{
s[i] = tmp[key[i] - '0' - 1];
}
free(tmp);
}
void main()
{
int n;
char str[100], key[100];
printf("input : ");
//请合法输入eg. AXZ 2 231
scanf("%s%d%s", str, n, key);
replace(str, n);
printf("str = %s\n", str);
disorder(str, key);
printf("str = %s\n", str);
}
#includestdio.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]);
}
}
#include stdio.h
#include stdlib.h
void replace(char *src, int n)
{
char *s = src;
n = n % 26;
while(*s != 0)
{
*s = *s + n;
if(*s 'Z') *s -= 26;
s++;
}
}
void disorder(char *s, char *key)
{
int len = 0 , i = 0;
char *tmp;
while(s[len++] != 0);
tmp = (char*)malloc(sizeof(char) * (len));
while(i len) tmp[i] = s[i++];
for(i = 0; i len - 1; i++)
{
s[i] = tmp[key[i] - '0' - 1];
}
free(tmp);
}
void main()
{
int n;
char str[100], key[100];
printf("input str n order : ");
//请合法输入eg. AXZ 2 231
scanf("%s%d%s", str, n, key);
replace(str, n);
printf("str = %s\n", str);
disorder(str, key);
printf("str = %s\n", str);
}
1、在我们的编辑页面输入以下代码。
2、需要将其分成两部分进行代码的编写,因为我们通过观察会发现一部分是顺着算,一部分是逆着算,所以我们必须要分两部分来完成源代码的编辑。
3、先对“将字母A变成字母G,a变成g,B变成H,b变成h”这一部分进行源代码的编写。
4、再对第二个部分“U变成A,V变成B”来进行编写,在整个程序,我们都可以直接用IF判断语句来进行判断输出结果即可。
5、最后,我们的编代码编写完成后,点击“运行”,弹出输入页面之后,在输入面板输入任意一个电文字符,然后点击回车键即可得出我们的对应的相应密码。
Private Sub Command1_Click()
Dim s As String
s = InputBox("请输入一段西文,我来加密。")
s1 = 加密(s)
Print "原文为:"; s
Print "加密为:"; s1
End Sub
Private Function 加密(原文 As String) As String
加密 = ""
For i = 1 To Len(原文)
字符 = Mid(原文, i, 1)
If 字符 = "a" And 字符 = "z" Then
字码 = Asc(字符) + 5
If 字码 "z" Then 字码 = 字码 - 26
新字符 = Chr(字码)
ElseIf 字符 = "A" And 字符 = "Z" Then
字码 = Asc(字符) + 5
If 字码 "Z" Then 字码 = 字码 - 26
新字符 = Chr(字码)
Else
新字符 = 字符
End If
加密 = 加密 新字符
Next i
End Function