-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <iostream> | ||
|
||
void encrypt(char* source, char* encrypted) | ||
{ | ||
while (*source != '\0') | ||
{ | ||
*encrypted = 158 - *source; | ||
source++; | ||
encrypted++; | ||
} | ||
} | ||
|
||
void decrypt(char* encrypted, char* source) | ||
{ | ||
while (*encrypted != '\0') | ||
{ | ||
*source = 158 - *encrypted; | ||
source++; | ||
encrypted++; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
printf("请输入需要加密字符串的长度:"); | ||
int n = 0; | ||
std::cin >> n; | ||
char* a = new char[n + 1](); | ||
char* b = new char[n + 1](); | ||
scanf("%s", a); | ||
encrypt(a, b); | ||
printf("加密后的字符串为:"); | ||
printf("%s\n", b); | ||
printf("请输入需要解密的字符串的长度:"); | ||
int s = 0; | ||
scanf("%d", &s); | ||
char* c = new char[n + 1](); | ||
char* d = new char[n + 1](); | ||
printf("需要解密的字符串为:"); | ||
scanf("%s", c); | ||
decrypt(c, d); | ||
printf("解密后的字符串为:"); | ||
printf("%s", d); | ||
} |