|
发表于 2020-10-19 18:28:13
|
显示全部楼层
也许,这个代码更加实用
- #include <stdio.h>
- char encrypt(char c)
- {
- if(c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '0' && c <= '9') {
- if(c >= 'W' && c <= 'Z' || c >= 'w' && c <= 'z' || c >= '6' && c <= '9') {
- if(c >= 'W' && c <= 'Z' || c >= 'w' && c <= 'z') c -= 26 ;
- else c -= 10 ;
- }
- c += 4 ;
- }
- return c ;
- }
- char decrypt(char c)
- {
- if(c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '0' && c <= '9') {
- if(c >= 'A' && c <= 'D' || c >= 'a' && c <= 'd' || c >= '0' && c <= '3') {
- if(c >= 'A' && c <= 'D' || c >= 'a' && c <= 'd') c += 26 ;
- else c += 10 ;
- }
- c -= 4 ;
- }
- return c ;
- }
- int main(void)
- {
- char c ;
- int iCounter = 1 ;
- printf(" Input your code : ") ;
- do {
- if((c = getchar()) != '\n') {
- if(iCounter == 1) printf("Its real code is : ") ;
- printf("%c" , encrypt(c)) ;
- iCounter ++ ;
- } else {
- break ;
- }
- } while(true) ;
- printf("\n") ;
- iCounter = 1 ;
- printf(" Input your code : ") ;
- do {
- if((c = getchar()) != '\n') {
- if(iCounter == 1) printf("Its real code is : ") ;
- printf("%c" , decrypt(c)) ;
- iCounter ++ ;
- } else {
- break ;
- }
- } while(true) ;
- printf("\n") ;
- }
复制代码
下面是编译、运行实况:
- D:\00.Excise\C>g++ -o x4 x4.c
- D:\00.Excise\C>x4
- Input your code : Hello , I Love You !
- Its real code is : Lipps , M Pszi Csy !
- Input your code : Lipps , M Pszi Csy !
- Its real code is : Hello , I Love You !
- D:\00.Excise\C>
复制代码
|
|