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

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

Luz6年前 (2019-11-29)ELSE8804
  1. #include<stdio.h>
  2. #include<string.h>
  3. char key[10][5]={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
  4. char keyboard[11]="qwertyuiop";
  5. int encode(char a[]){
  6.  for(int i=0;i<strlen(a);i++){
  7.   for(int j=2;j<=9;j++){
  8.    for(int k=0;k<strlen(key[j]);k++){
  9.     if(a[i]==key[j][k]){
  10.      for(int l =0;l<=k;l++){
  11.       printf("%c",keyboard[j-1]);
  12.      }
  13.      printf(" ");
  14.      break;
  15.     }
  16.    }
  17.   }
  18.  } 
  19. }
  20. int decode(char a[]){
  21.  int i=0;
  22.  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"};
  23.  while(i<strlen(a)){
  24.   char b[5]={'\0','\0','\0','\0','\0'};
  25.   int o=0;
  26.   while(a[i]!=' '){
  27.    b[o]=a[i];
  28.    i++;
  29.    o++;
  30.   }
  31.   for(int j=0;j<26;j++){
  32.    if(!strncmp(b,c[j],strlen(b)+1)){
  33.     printf("%c",'a'+j);
  34.     break;
  35.    }
  36.    
  37.   }
  38.   i++;
  39.  }
  40. }
  41. int main(){
  42.  char input[1000];
  43.  char choice;
  44.  printf("0:encode\n1:decode\n");
  45.  scanf("%d\n",&choice);
  46.  if(choice==0){
  47.   gets(input);
  48.   encode(input); 
  49.  }
  50.  if(choice==1){
  51.   gets(input);
  52.   input[strlen(input)]=' ';
  53.   input[strlen(input)+1]='\0';
  54.   decode(input); 
  55.  }
  56. }

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

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

评论列表

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

i

发表评论

访客

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