第一行输入一个长度为
的字符串
,代表给定的明文字符串;
第二行输入一个长度为
的字符串
,代表给定的密文字符串。
除此之外,保证字符串
和
中仅包含英文字母和数字。
第一行输出一个字符串,代表加密后的
。
第二行输出一个字符串,代表解密后的
。
abcdefg1 0BCDEFGH
BCDEFGH2 9abcdefg
#include<iostream>
#include<string>
using namespace std;
void Enpt(string s){
for(int i=0;i<s.size();i++){
if(s[i] >='a' && s[i]<='z'){
s[i] = (s[i]-'a'+1)%26+'A';
}
else if(s[i]>='A' && s[i]<='Z'){
s[i] =(s[i]-'A'+1)%26+'a';
}
else if(s[i]>='0' && s[i]<='9'){
s[i]= (s[i]-'0'+1)%10+'0';
}
}
cout<<s<<endl;
}
void unEnpt(string s){
for(int i=0;i<s.size();i++){
if(s[i] >='a' && s[i]<='z'){
s[i] = (s[i]-'a'+25)%26+'A';
}
else if(s[i]>='A' && s[i]<='Z'){
s[i] =(s[i]-'A'+25)%26+'a';
}
else if(s[i]>='0' && s[i]<='9'){
s[i]= (s[i]-'0'+9)%10+'0';
}
}
cout<<s<<endl;
}
int main(){
string s1,s2;
while(cin>>s1){
cin>>s2;
Enpt(s1);
unEnpt(s2);
}
return 0;
}
#include<iostream> #include<iomanip> #include<string> #include<vector> using namespace std; void Encrypt (string str) { int len = str.size(); for(int i=0; i<len; i++) { if(str[i]<='9'&&str[i]>='0') { if(str[i]<'9') { str[i]=str[i]+1; } else str[i]='0'; } else if(str[i]<='z'&&str[i]>='a') { if(str[i]<'z') { str[i]=str[i]-'a'+'A'+1; } else { str[i]='A'; } } else if(str[i]<='Z'&&str[i]>='A') { if(str[i]<'Z') { str[i]=str[i]-'A'+'a'+1; } else { str[i]='a'; } } } cout<<str<<endl; } int unEncrypt(string str) { int len = str.size(); for(int i=0; i<len; i++) { if(str[i]<='9'&&str[i]>='0') { if(str[i]>'0') { str[i]=str[i]-1; } else str[i]='9'; } else if(str[i]<='z'&&str[i]>='a') { if(str[i]>'a') { str[i]=str[i]-'a'+'A'-1; } else { str[i]='Z'; } } else if(str[i]<='Z'&&str[i]>='A') { if(str[i]>'A') { str[i]=str[i]-'A'+'a'-1; } else { str[i]='z'; } } } cout<<str<<endl; return 0; } int main() { string str1; string str2; while(getline(cin,str1)) { getline(cin,str2); Encrypt(str1); unEncrypt(str2); } return 0; }
s1 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" s2 = "1234567890BCDEFGHIJKLMNOPQRSTUVWXYZAbcdefghijklmnopqrstuvwxyza" d1 = dict(zip(s1,s2)) d2 = dict(zip(s2,s1)) str1, str2 = input(), input() for i in str1: print(d1[i],end="") print() for j in str2: print(d2[j],end='')
while True:
try:
encode = input()
decode = input()
length_encode, length_decode = len(encode), len(decode)
output_encode, output_decode = "", ""
# encode
for i in range(length_encode):
temp = encode[i]
if encode[i].isalpha():
if ord("a")<=ord(temp)<ord("z"):
temp = (chr(ord(temp)+1)).upper()
elif ord(temp) == ord("z"):
temp = "A"
elif ord("A")<=ord(temp)<ord("Z"):
temp = (chr(ord(temp)+1)).lower()
elif ord(temp) == ord("Z"):
temp = "a"
elif temp.isdigit():
temp = str((int(encode[i])+1)%10)
output_encode = output_encode + temp
print(output_encode)
# decode
for i in range(length_decode):
temp = decode[i]
if decode[i].isalpha():
if ord("a")<ord(temp)<=ord("z"):
temp = (chr(ord(temp)-1)).upper()
elif temp == "a":
temp = "Z"
elif ord("A")<ord(temp)<=ord("Z"):
temp = (chr(ord(temp)-1)).lower()
elif temp == "A":
temp = "z"
elif decode[i].isdigit():
temp = str((int(temp)+9)%10)
output_decode = output_decode + temp
print(output_decode)
except:
break #非常暴力的算法 l1 = ['a','b','c','d','e','f','g', 'h','i','j','k','l','m','n', 'o','p','q','r','s','t', 'u','v','w','x','y','z', 'A','B','C','D','E','F','G', 'H','I','J','K','L','M','N', 'O','P','Q','R','S','T', 'U','V','W','X','Y','Z', '0','1','2','3','4','5','6','7','8','9'] l2 = ['B','C','D','E','F','G','H', 'I','J','K','L','M','N','O', 'P','Q','R','S','T','U', 'V','W','X','Y','Z','A', 'b','c','d','e','f','g','h', 'i','j','k','l','m','n','o', 'p','q','r','s','t','u', 'v','w','x','y','z','a', '1','2','3','4','5','6','7','8','9','0'] jia = input() jia1 = [] jie = input() jie1 = [] for i in jia : if i in l1 : jia1.append(l2[l1.index(i)]) for i in jia1 : print(i,end = '') print() for i in jie : if i in l2 : jie1.append(l1[l2.index(i)]) for i in jie1 : print(i,end = '')
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String plainText = sc.nextLine(); // 明文
String cipherText = sc.nextLine(); // 密文
encryptStr(plainText); // 加密
System.out.println();
decryptStr(cipherText); // 解密
}
}
// 加密字符串
public static void encryptStr(String plainText) {
for (int i = 0; i < plainText.length(); i++) {
char ch = plainText.charAt(i);
if (ch >= 'a' && ch < 'z') {
ch = (char)(ch + 1 - 32); // +1并转为大写
} else if (ch >= 'A' && ch < 'Z') {
ch = (char)(ch + 1 + 32); // +1并转为小写
} else if (ch >= '0' && ch < '9') {
ch = (char)(ch + 1); // +1
} else if (ch == 'z') {
ch = 'A'; // 小写z ==> A
} else if (ch == 'Z') {
ch = 'a'; // 大写Z ==> Z
} else if (ch == '9') {
ch = '0'; // 9 ==> 0
}
System.out.print(ch);
}
}
// 解密字符串
public static void decryptStr(String cipherText) {
for (int i = 0; i < cipherText.length(); i++) {
char ch = cipherText.charAt(i);
if (ch > 'a' && ch <= 'z') {
ch = (char)(ch - 1 - 32); // -1并转为大写
} else if (ch > 'A' && ch <= 'Z') {
ch = (char)(ch - 1 + 32); // -1并转为小写
} else if (ch > '0' && ch <= '9') {
ch = (char)(ch - 1); // -1
} else if (ch == 'a') {
ch = 'Z'; // 小写a ==> Z
} else if (ch == 'A') {
ch = 'z'; // 大写A ==> z
} else if (ch == '0') {
ch = '9'; // 0 ==> 9
}
System.out.print(ch);
}
}
} #include<stdio.h>
#include<string.h>
int main(){
void encrypt(); //声明加密函数
void decrypt(); //声明解密函数
char str1[1001]={'\0'};
char str2[1001]={'\0'};
scanf("%s",str1);
scanf("%s",str2);
encrypt(str1);
decrypt(str2);
}
void encrypt(char str[1001]){
int len = strlen(str);
for(int i=0;i<len;i++){
if(str[i]>='a'&&str[i]<='y')
printf("%c",str[i]-32+1);
else if(str[i]>='A'&&str[i]<='Y')
printf("%c",str[i]+32+1);
else if(str[i]=='z')
printf("A");
else if(str[i]=='Z')
printf("a");
else if(str[i]>='0'&&str[i]<='8')
printf("%c",str[i]+1);
else if(str[i]=='9')
printf("0");
}printf("\n");
}
void decrypt(char str[1001]){
int len = strlen(str);
for(int i=0;i<len;i++){
if(str[i]>='b'&&str[i]<='z')
printf("%c",str[i]-32-1);
else if(str[i]>='B'&&str[i]<='Z')
printf("%c",str[i]+32-1);
else if(str[i]=='A')
printf("z");
else if(str[i]=='a')
printf("Z");
else if(str[i]>='1'&&str[i]<='9')
printf("%c",str[i]-1);
else if(str[i]=='0')
printf("9");
}printf("\n");
} #include<iostream>
#include<string>
using namespace std;
string encryp_str(string str){//加密
for(int i = 0;i < str.size();i++){
if(str[i]<='Z'&&str[i]>='A'){
str[i] = str[i] - 'A' +'a';
str[i] = (str[i] + 1 - 'a')%26 + 'a';
}
else if(str[i]<='z'&&str[i]>='a'){
str[i] = str[i] - 'a' +'A';
str[i] = (str[i] + 1 - 'A')%26 + 'A';
}
else if(str[i]>='0'&&str[i]<='9'){
str[i] = (str[i] + 1 - '0')%10 + '0';
}
}
return str;
}
string deciph_str(string str){//解密
for(int i = 0;i < str.size();i++){
if(str[i]<='Z'&&str[i]>='A'){
str[i] = str[i] - 'A' +'a';
str[i] = (str[i] - 1 - 'a' + 26 ) % 26 + 'a';
}
else if(str[i]<='z'&&str[i]>='a'){
str[i] = str[i] - 'a' +'A';
str[i] = (str[i] - 1 - 'A' + 26 ) % 26 + 'A';
}
else if(str[i]>='0'&&str[i]<='9'){
str[i] = (str[i] - 1 - '0' + 10 ) % 10 + '0';
}
}
return str;
}
int main(){
string str1;
string str2;
while(cin>>str1){
cin>>str2;
cout<< encryp_str(str1)<<endl;
cout<< deciph_str(str2)<<endl;
}
} while True: try: mingwen = input() miwen = input() res1,res2 = "","" for i in mingwen: if i.isdigit(): if i != "9": res1 += str(int(i) + 1) else: res1 += "0" if i.isalpha(): if i.lower() != "z": if i.islower(): res1 += chr(ord(i.upper())+1) else: res1 += chr(ord(i.lower())+1) else: if i.islower(): res1 += "A" else: res1 += "a" print(res1) for i in miwen: if i.isdigit(): if i != "0": res2 += str(int(i) - 1) else: res2 += "9" if i.isalpha(): if i.lower() != "a": if i.islower(): res2 += chr(ord(i.upper())-1) else: res2 += chr(ord(i.lower())-1) else: if i.islower(): res2 += "Z" else: res2 += "z" print(res2) except: break
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
System.out.println(encode(sc.nextLine(), true));
System.out.println(encode(sc.nextLine(), false));
}
}
public static String encode(String str, boolean flag) {
String result = "";
for(char c : str.toCharArray()) {
// 数字
if (c >= '0' && c <='9') {
if (c == '9' && flag) {
result += '0';
} else if (c == '0' && !flag){
result += '9';
} else {
if (flag) {
result += (char)(c+1);
} else {
result += (char)(c-1);
}
}
continue;
}
// 小写字母
if (c >= 'a' && c <= 'z') {
if (c == 'z' && flag) {
result += 'A';
} else if (c == 'a' && !flag) {
result += 'Z';
}else {
if (flag) {
result += (char)(c-31);
} else {
result += (char)(c-33);
}
}
continue;
}
// 大写字母
if (c >= 'A' && c <= 'Z') {
if (c == 'Z' && flag) {
result += 'a';
} else if (c == 'A' || !flag) {
result += 'z';
}else {
if (flag) {
result += (char)(c+33);
} else {
result += (char)(c+31);
}
}
continue;
}
result += c;
}
return result;
}
} import java.util.Scanner;
/**
* @author Yuliang.Lee
* @version 1.0
* @date 2021/9/6 12:08
* 字符串加解密:
1、对输入的字符串进行加解密,并输出。
第一行输入是要加密的密码,第二行输入是加过密的密码
2、加密方法为:
当内容是英文字母时则用该英文字母的后一个字母替换,同时字母变换大小写,如字母a时则替换为B;字母Z时则替换为a;
当内容是数字时则把该数字加1,如0替换1,1替换2,9替换0;
其他字符不做变化。
3、解密方法为加密的逆过程。
* 示例:
输入
abcdefg
BCDEFGH
输出
BCDEFGH
abcdefg
*/
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
String plaintext = in.nextLine();
String ciphertext = in.nextLine();
for (char e : encrypt(plaintext)) {
System.out.print(e);
}
System.out.println();
for (char d : decrypt(ciphertext)) {
System.out.print(d);
}
System.out.println();
}
}
public static char[] encrypt(String input) {
char[] encryption = new char[input.length()];
for (int i = 0; i < input.length(); i++) {
char ch = input.charAt(i);
if (ch >= 'A' && ch <= 'Z') {
if (ch == 'Z') {
ch = 'a';
}
else {
ch = (char) (ch + 33);
}
} else if (ch >= 'a' && ch <= 'z') {
if (ch == 'z') {
ch = 'A';
}
else {
ch = (char) (ch - 31);
}
} else if (ch >= '0' && ch <= '9') {
if (ch == '9') {
ch = '0';
}
else {
ch = (char) (ch+1);
}
}
encryption[i] = ch;
}
return encryption;
}
public static char[] decrypt(String input) {
char[] decryption = new char[input.length()];
for (int i = 0; i < input.length(); i++) {
char ch = input.charAt(i);
if (ch >= 'A' && ch <= 'Z') {
if (ch == 'A') {
ch = 'z';
}
else {
ch = (char) (ch + 31);
}
} else if (ch >= 'a' && ch <= 'z') {
if (ch == 'a') {
ch = 'Z';
}
else {
ch = (char) (ch - 33);
}
} else if (ch >= '0' && ch <= '9') {
if (ch == '0') {
ch = '9';
}
else {
ch = (char) (ch-1);
}
}
decryption[i] = ch;
}
return decryption;
}
}
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String plaintext = sc.nextLine();
String pwd = sc.nextLine();
System.out.println(encrpt(plaintext));
System.out.println(decrpt(pwd));
}
}
public static String decrpt(String pwd){
char[] arr = pwd.toCharArray();
for(int i = 0 ; i < arr.length ; i++){
if(arr[i] >= '0' && arr[i] <= '9'){
if(arr[i] == '0'){
arr[i] = '9';
}else{
arr[i] = (char)(arr[i] - 1 );
}
continue;
}
if(arr[i] >= 'a' && arr[i] <= 'z'){
if(arr[i] == 'a'){
arr[i] = 'Z';
}else{
arr[i] = (char)(arr[i] - 33);
}
continue;
}
if(arr[i] >= 'A' && arr[i] <= 'Z'){
if(arr[i] == 'A'){
arr[i] = 'z';
}else{
arr[i] = (char)(arr[i] + 31);
}
continue;
}
}
return String.valueOf(arr);
}
public static String encrpt(String plaintext){
char[] arr = plaintext.toCharArray();
for(int i = 0 ; i < arr.length ; i++){
if(arr[i] >= '0' && arr[i] <= '9'){
if(arr[i] == '9'){
arr[i] = '0';
}else{
arr[i] = (char)(arr[i] + 1);
}
continue;
}
if(arr[i] >= 'a' && arr[i] <= 'z'){
if(arr[i] == 'z'){
arr[i] = 'A';
}else{
Character.toUpperCase(arr[i]);
arr[i] = (char)(arr[i] - 31);
}
continue;
}
if(arr[i] >= 'A' && arr[i] <= 'Z'){
if(arr[i] == 'Z'){
arr[i] = 'a';
}else{
Character.toLowerCase(arr[i]);
arr[i] = (char)(arr[i] + 33);
}
continue;
}
}
return String.valueOf(arr);
}
} #include<iostream>
using namespace std;
string Encode(string A){
for(int i=0;i<A.size();i++){
if(isalpha(A[i])){
if(islower(A[i])){
if(A[i]=='z') A[i]='A';
else A[i]=toupper(A[i])+1;
}
else{
if(A[i]=='Z') A[i]='a';
else A[i]=tolower(A[i])+1;
}
}
else if(isdigit(A[i])){
if(A[i]=='9') A[i]='0';
else A[i]++;
}
}
return A;
}
string Decode(string A){
for(int i=0;i<A.size();i++){
if(isalpha(A[i])){
if(islower(A[i])){
if(A[i]=='a') A[i]='Z';
else A[i]=toupper(A[i])-1;
}
else{
if(A[i]=='A') A[i]='z';
else A[i]=tolower(A[i])-1;
}
}
else if(isdigit(A[i])){
if(A[i]=='0') A[i]='9';
else A[i]--;
}
}
return A;
}
int main(){
string forEncode, forDecode;
while(cin>>forEncode>>forDecode){
cout<<Encode(forEncode)<<endl;
cout<<Decode(forDecode)<<endl;
}
} #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char str[500] = {0};
char str_out[500] = {0};
char str1[500] = {0};
while(gets(str))
{
gets(str1);
memset(str_out, '\0',sizeof(str_out));
for(int i = 0; str[i] != '\0'; i++)
{
if(str[i] >= 'a' && str[i] <= 'z')
{
str_out[i] = (str[i]%'a'+1)%26+'A';
}
else if(str[i] >= 'A' && str[i] <= 'Z')
{
str_out[i] = (str[i]%'A'+1)%26+'a';
}
else if(str[i] >= '0' && str[i] <= '9')
{
str_out[i] = (str[i]%'0'+1)%10+'0';
}
}
printf("%s\n", str_out);
memset(str_out, '\0',sizeof(str_out));
for(int i = 0; str1[i] != '\0'; i++)
{
if(str1[i] >= 'a' && str1[i] <= 'z')
{
str_out[i] = (str1[i]%'a'-1+26)%26 +'A';
}
else if(str1[i] >= 'A' && str1[i] <= 'Z')
{
str_out[i] = (str1[i]%'A'-1+26)%26 +'a';
}
else if(str1[i] >= '0' && str1[i] <= '9')
{
str_out[i] = (str1[i]%'0'-1+10)%10 +'0';
}
}
printf("%s\n", str_out);
}
} #include<iostream>
#include<stdio.h>
#include<cstring>
#include<string.h>
using namespace std;
void encrypt(string& s) {
//加密
int len=s.size();
for(int i=0;i<len;++i) {
if(s[i]>='a' && s[i]<='z') {
//小写字母
s[i]=('A'+(s[i]-'a'+1)%26); //转为后一个,且大小写转换
} else if(s[i]>='A' && s[i]<='Z') {
s[i]=('a'+(s[i]-'A'+1)%26);
} else {
//数字
s[i]=('0'+(s[i]-'0'+1)%10);
}
}
}
void decrypt(string& s) {
//解密
int len=s.size();
for(int i=0;i<len;++i) {
if(s[i]>='a' && s[i]<='z') {
//小写字母
s[i]=('A'+(s[i]-'a'+25)%26); //转为后一个,且大小写转换
} else if(s[i]>='A' && s[i]<='Z') {
s[i]=('a'+(s[i]-'A'+25)%26);
} else {
//数字
s[i]=('0'+(s[i]-'0'+9)%10);
}
}
}
int main()
{
string a;
while(cin>>a) {
encrypt(a); //对a加密
cout<<a<<endl;
string b;
cin>>b;
decrypt(b); //对b解密
cout<<b<<endl;
}
return 0;
} import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
String code1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
String code2 = "bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA1234567890";
while (cin.hasNext()) {
String encode = cin.next();
String decode = cin.next();
StringBuilder sb1 = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
for (int i = 0; i < encode.length(); i++) {
sb1.append(code2.charAt(code1.indexOf(encode.charAt(i))));
}
for (int i = 0; i < decode.length(); i++) {
sb2.append(code1.charAt(code2.indexOf(decode.charAt(i))));
}
System.out.println(sb1);
System.out.println(sb2);
}
}
} import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String code1;
while((code1 = br.readLine()) != null){
code1 = code1.trim();
// 加密
StringBuilder encode = new StringBuilder();
for(int i = 0; i < code1.length(); i++){
if(code1.charAt(i) >= 'a' && code1.charAt(i) <= 'z'){
if(code1.charAt(i) != 'z')
encode.append((char)(code1.charAt(i) + 1 - 32));
else
encode.append('A');
}else if(code1.charAt(i) >= 'A' && code1.charAt(i) <= 'Z'){
if(code1.charAt(i) != 'Z')
encode.append((char)(code1.charAt(i) + 1 + 32));
else
encode.append('a');
}else if(code1.charAt(i) >= '0' && code1.charAt(i) <= '9'){
if(code1.charAt(i) != '9')
encode.append((char)(code1.charAt(i) + 1));
else
encode.append('0');
}else
encode.append(code1.charAt(i));
}
String code2 = br.readLine().trim();
// 解密
StringBuilder decode = new StringBuilder();
for(int i = 0; i < code2.length(); i++){
if(code2.charAt(i) >= 'a' && code2.charAt(i) <= 'z'){
if(code2.charAt(i) != 'a')
decode.append((char)(code2.charAt(i) - 1 - 32));
else
decode.append('Z');
}else if(code2.charAt(i) >= 'A' && code2.charAt(i) <= 'Z'){
if(code2.charAt(i) != 'A')
decode.append((char)(code2.charAt(i) - 1 + 32));
else
decode.append('z');
}else if(code2.charAt(i) >= '0' && code2.charAt(i) <= '9'){
if(code2.charAt(i) != '0')
decode.append((char)(code2.charAt(i) - 1));
else
decode.append('9');
}else
decode.append(code2.charAt(i));
}
System.out.println(encode);
System.out.println(decode);
}
}
} import java.util.Scanner;
public class Main {
private static final String ORIGIN = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
private static final String ENCRYPTED = "bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA1234567890";
private static String apply(String input, boolean isEncrypt) {
String src = isEncrypt ? ORIGIN : ENCRYPTED;
String dst = isEncrypt ? ENCRYPTED : ORIGIN;
StringBuilder sb = new StringBuilder();
for (char c : input.toCharArray()) {
int index = src.indexOf(c);
sb.append(index == -1 ? c : dst.charAt(index));
}
return sb.toString();
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
System.out.println(apply(sc.nextLine(), true));
System.out.println(apply(sc.nextLine(), false));
}
}
} #include <iostream>
using namespace std;
string ORIGIN = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
string ENCRYPTED = "bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA1234567890";
string applyCipher(string input, bool isEncrypt) {
string res;
string src = isEncrypt ? ORIGIN : ENCRYPTED;
string dst = isEncrypt ? ENCRYPTED : ORIGIN;
for (char c:input) {
int index = src.find(c);
res += (index == -1) ? c : dst[index];
}
return res;
}
int main() {
string origin, encrypted;
while (cin >> origin >> encrypted) {
cout << applyCipher(origin, true) << endl << applyCipher(encrypted, false) << endl;
}
return 0;
} #include <stdio.h>
#include <memory.h>
#include <string.h>
#define SIZE 4096
char *ORIGIN = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
char *ENCRYPTED = "bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA1234567890";
void applyCipher(char *in, char *out, int isEncrypt) {
char *src = isEncrypt ? ORIGIN : ENCRYPTED;
char *dst = isEncrypt ? ENCRYPTED : ORIGIN;
char *p = NULL;
for (int i = 0; i < strlen(in); i++) {
p = strchr(src, in[i]);
out[i] = (p == NULL) ? in[i] : dst[p - src];
}
}
int main() {
char origin[SIZE] = {0}, encrypted[SIZE] = {0}, result[SIZE] = {0};
while (scanf("%s %s", origin, encrypted) != EOF) {
applyCipher(origin, result, 1);
printf("%s\n", result);
memset(result, 0, SIZE);
applyCipher(encrypted, result, 0);
printf("%s\n", result);
memset(origin, 0, SIZE);
memset(encrypted, 0, SIZE);
}
return 0;
} import java.util.*;
public class Main{
public static char[] alpRef = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
public static int[] intRef = {0,1,2,3,4,5,6,7,8,9};
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
Main a = new Main();
while (scanner.hasNext()){
System.out.println(a.encrypt(scanner.next()));
System.out.println(a.decrypt(scanner.next()));
}
}
public String encrypt(String string){
StringBuilder output = new StringBuilder();
for (int i = 0; i < string.length(); i++){
if (string.charAt(i)-'A' < 0){
int index = string.charAt(i)-'0' == 9 ? 0 : string.charAt(i)-'0' + 1;
output.append(intRef[index]);
}else{
if (string.charAt(i)-'a' < 0){
int index = Character.toLowerCase(string.charAt(i))-'a' == 25 ? 0 : Character.toLowerCase(string.charAt(i))-'a' + 1;
output.append(alpRef[index]);
}else{
int index = string.charAt(i)-'a' == 25 ? 0 : string.charAt(i)-'a' + 1;
output.append(Character.toUpperCase(alpRef[index]));
}
}
}
return output.toString();
}
public String decrypt(String string){
StringBuilder output = new StringBuilder();
for (int i = 0; i < string.length(); i++){
if (string.charAt(i)-'A' < 0){
int index = string.charAt(i)-'0' == 0 ? 9 : string.charAt(i)-'0' - 1;
output.append(intRef[index]);
}else{
if (string.charAt(i)-'a' < 0){
int index = Character.toLowerCase(string.charAt(i))-'a' == 0 ? 25 : Character.toLowerCase(string.charAt(i))-'a' - 1;
output.append(alpRef[index]);
}else{
int index = string.charAt(i)-'a' == 0 ? 25 : string.charAt(i)-'a' - 1;
output.append(Character.toUpperCase(alpRef[index]));
}
}
}
return output.toString();
}
}