-->
当前位置:首页 > ELSE > 正文内容

9键26键键盘密码 加密解密脚本

Luz5年前 (2019-11-29)ELSE8102
#include<stdio.h>
#include<string.h>
char key[10][5]={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
char keyboard[11]="qwertyuiop";
int encode(char a[]){
 for(int i=0;i<strlen(a);i++){
  for(int j=2;j<=9;j++){
   for(int k=0;k<strlen(key[j]);k++){
    if(a[i]==key[j][k]){
     for(int l =0;l<=k;l++){
      printf("%c",keyboard[j-1]);
     }
     printf(" ");
     break;
    }
   }
  }
 } 
}
int decode(char a[]){
 int i=0;
 char c[26][5]={"w","ww","www","e","ee","eee","r","rr","rrr","t","tt","ttt","y","yy","yyy","u","uu","uuu","uuuu","i","ii","iii","o","oo","ooo","oooo"};
 while(i<strlen(a)){
  char b[5]={'\0','\0','\0','\0','\0'};
  int o=0;
  while(a[i]!=' '){
   b[o]=a[i];
   i++;
   o++;
  }
  for(int j=0;j<26;j++){
   if(!strncmp(b,c[j],strlen(b)+1)){
    printf("%c",'a'+j);
    break;
   }
   
  }
  i++;
 }
}
int main(){
 char input[1000];
 char choice;
 printf("0:encode\n1:decode\n");
 scanf("%d\n",&choice);
 if(choice==0){
  gets(input);
  encode(input); 
 }
 if(choice==1){
  gets(input);
  input[strlen(input)]=' ';
  input[strlen(input)+1]='\0';
  decode(input); 
 }
}

使用26键键盘的最上面一行的英文字母分别映射到九键键盘

字母重复次数为9键键盘的第几个字母

评论列表

访客
访客
4年前 (2020-06-09)

i

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。