鱼C论坛

 找回密码
 立即注册
查看: 3273|回复: 13

关于vigenger加密问题 (C语言)

[复制链接]
发表于 2020-3-31 11:45:40 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 北有樵先生 于 2020-4-8 15:10 编辑

问题是输出期望的结果后,有有一些不符合期望的字符跟在其后面。具体描述在代码最后。代码如下:

  1. # include <stdio.h>
  2. # include <stdlib.h>
  3. # include <time.h>
  4. # include <string.h>


  5. # define OK         1
  6. # define ERROR  0
  7. # define SIZE   16  

  8. typedef char Elemtype ;
  9. typedef struct node
  10. {
  11.         Elemtype elem ;
  12.         struct node *next ;
  13.         struct node *previous ;
  14. }node , *Linklist ;

  15. static char* input_plaintext (void) ;
  16. static void create_BidCirlinklist ( Linklist *L) ;
  17. static int * create_CipherKey ( int len ) ;
  18. static node* find_ch (Linklist L , Elemtype ch)  ;
  19. static void create_one_cipher (node*S , int n , Elemtype *ch) ;
  20. static Elemtype* create_Cipher (Linklist L, int len , int *key , char * passward)  ;

  21. int main (void)
  22. {
  23.         FILE *fp ;
  24.         int len , *key , i;
  25.         Elemtype *password , *new_password ;
  26.         Linklist l = NULL;
  27.         if ( (fp = fopen("Encrypted.txt", "wb")) == NULL)
  28.         {
  29.                 printf("打开文件失败\n") ;
  30.                 exit(EXIT_FAILURE) ;
  31.         }
  32.         password = input_plaintext() ;
  33.         len = strlen(password) ;
  34.         key = create_CipherKey(len) ;   
  35.         fwrite(password,sizeof(char),len,fp) ;
  36.         fwrite(key,sizeof(int),len,fp) ;
  37.         fclose(fp) ; // 至此写入明文和密匙,以二进制的形式
  38.         create_BidCirlinklist(&l) ;
  39.         new_password = create_Cipher(l,len,key,password) ;
  40.         printf ("%s\n",password) ;    // 从这里开始便是验证输入和输出结果
  41.         i = 0 ;
  42.         while ( i < len )
  43.         {
  44.                 printf("%2d ",key[i]) ;
  45.                 i++;
  46.         }
  47.         printf("\n") ;
  48.         for( i = 0; i < len ; i++)
  49.         {
  50.                 printf("%c ",new_password[i]) ;  // 单个字母输出并无问题
  51.         }
  52.         printf("\n") ;
  53.         printf("%s\n",new_password) ;  // 问题出现在这个输出上
  54.         free(new_password);
  55.         free(key);
  56.         return 0;
  57. }
  58. // 输入明文
  59. static char* input_plaintext (void)
  60. {
  61.         int Len ;
  62.         char *Str ,*str;
  63.         str = (char*)malloc( SIZE * sizeof(char)) ;
  64.         printf ("请输入明文(至多输入16位):") ;
  65.         scanf ("%s",str) ;
  66.         Len = strlen(str) ;
  67.         Str = (char*)malloc( Len * sizeof(char)) ;
  68.         strcpy(Str,str) ;
  69.         return Str ;
  70. }
  71. // 建立解密环
  72. static void create_BidCirlinklist ( Linklist *L) // L是指针的指针
  73. {
  74.         node *flag , *new_node ;
  75.         int i = 0 ;
  76.         while ( i< 26 )
  77.         {
  78.                 new_node = (node *)malloc(sizeof(node )) ;
  79.                 new_node->elem = 'A'+i ;
  80.                 if ((*L) == NULL )
  81.                 {
  82.                         flag = (*L) = new_node ;
  83.                         flag->next = flag->previous = NULL ;
  84.                 }
  85.                 else
  86.                 {
  87.                         new_node->next = flag->next ;
  88.                         flag->next = new_node ;
  89.                         new_node->previous = flag ;
  90.                         flag = new_node ;
  91.                 }
  92.                 i++ ;
  93.         }
  94.         flag->next = (*L) ;
  95.         (*L)->previous = flag ;
  96. }
  97. // 生成随机密匙
  98. static int * create_CipherKey ( int len )
  99. {
  100.         int i ;
  101.         int *Key = (int *)malloc(sizeof(int) * len) ;
  102.         time_t t;
  103.         srand(time(&t)) ;
  104.         for( i = 0 ; i < len ; i++)
  105.         {
  106.                 Key[i] = rand()%100 ;
  107.         }
  108.         return Key ;
  109. }

  110. // 生成密文
  111. static Elemtype* create_Cipher (Linklist L, int len , int *key , char * passward)  
  112. {
  113.         int i ;
  114.         Elemtype *new_cipher = (Elemtype*)malloc( sizeof(Elemtype)*len ) ;
  115.         node *flag ;
  116.         for ( i = 0 ; i < len ; i++)
  117.         {
  118.                 flag = find_ch(L , passward[i]) ;
  119.                 create_one_cipher(flag,key[i],&new_cipher[i]) ;
  120.         }
  121.         return new_cipher ;
  122. }

  123. // 找到对应的字母,便于生成新字母
  124. static node* find_ch (Linklist l , Elemtype ch)
  125. {
  126.         node *flag1 = l ;
  127.         if ( ch > 'Z')
  128.         {
  129.                 ch -= 32 ;
  130.         }
  131.         if ( ch <= 'M')
  132.         {
  133.                 while (flag1->elem != ch)
  134.                         flag1 = flag1->next ;
  135.         }
  136.         else
  137.         {
  138.                 while (flag1->elem != ch)
  139.                         flag1 = flag1->previous ;
  140.         }
  141.         return flag1 ;
  142. }

  143. // 生成新一位密文并用ch返回
  144. static void create_one_cipher (node*S , int n , Elemtype *ch)  // 当n的绝对值大于13时 向反方向移动 提高效率
  145. {
  146.         node *flag2 = S ;
  147.         if ( n > 0)
  148.         {
  149.                 n %= 26 ;
  150.                 if ( n >13)
  151.                 {
  152.                         while (n--)
  153.                                 flag2 = flag2->previous;
  154.                 }
  155.                 else
  156.                 {
  157.                         while (n--)
  158.                                 flag2 = flag2->next ;
  159.                 }       
  160.         }
  161.         else
  162.         {
  163.                 n %= -26 ;
  164.                 if ( n >13)
  165.                 {
  166.                         while (n++)
  167.                                 flag2 = flag2->previous;
  168.                 }
  169.                 else
  170.                 {
  171.                         while (n++)
  172.                                 flag2 = flag2->next ;
  173.                 }       
  174.         }
  175.         *ch = flag2->elem ;
  176. }
复制代码


我已经调试了,结果都正确,问题在于结果后会跟不相符的字符;

这个临界点出现在输入7个字母和8个字母,8个字符往后都会出现这些,而且越多,我已经调试完了,可以正常运行,单个字母进行输出,也可以得到结果

因为是新人所以不能上传图片,但程序可运行,可以尝试输入,谢谢
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-3-31 12:09:07 | 显示全部楼层
给出输入样例和输出结果,如果有必要,再指出哪里和你期望的结果不符
这样会对我调试程序很有帮助
还有代码写的也挺长了,该学一学调试程序的方法了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-31 14:16:33 | 显示全部楼层
本帖最后由 北有樵先生 于 2020-3-31 15:56 编辑
人造人 发表于 2020-3-31 12:09
给出输入样例和输出结果,如果有必要,再指出哪里和你期望的结果不符
这样会对我调试程序很有帮助
还有代 ...


你的前半句很有道理,是我对问题的描述不够,我已经改了,谢谢。不过我想说,一上来就质疑人啥都没干,这种行为很愚蠢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-31 16:57:08 | 显示全部楼层
北有樵先生 发表于 2020-3-31 14:16
你的前半句很有道理,是我对问题的描述不够,我已经改了,谢谢。不过我想说,一上来就质疑人啥都没干, ...

你修改后的结果也一样,对调试程序没有任何帮助
我期望的是像下面这样的
输入:abcd1234
输出:234abcd1+
我期望的输出是:1234abcd
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-31 18:40:53 | 显示全部楼层
发现了好多问题

  1. # include <stdio.h>
  2. # include <stdlib.h>
  3. # include <time.h>
  4. # include <string.h>


  5. # define OK         1
  6. # define ERROR  0
  7. # define SIZE   16  

  8. typedef char Elemtype ;
  9. typedef struct node
  10. {
  11.         Elemtype elem ;
  12.         struct node *next ;
  13.         struct node *previous ;
  14. }node , *Linklist ;

  15. static char* input_plaintext (void) ;
  16. static void create_BidCirlinklist ( Linklist *L) ;
  17. static int * create_CipherKey ( int len ) ;
  18. static node* find_ch (Linklist L , Elemtype ch)  ;
  19. static void create_one_cipher (node*S , int n , Elemtype *ch) ;
  20. static Elemtype* create_Cipher (Linklist L, int len , int *key , char * passward)  ;

  21. int main (void)
  22. {
  23.         FILE *fp ;
  24.         int len , *key , i;
  25.         Elemtype *password , *new_password ;
  26.         Linklist l = NULL;
  27.         srand(time(NULL)) ;     // 放在这里更好
  28.         if ( (fp = fopen("Encrypted.txt", "wb")) == NULL)
  29.         {
  30.                 printf("打开文件失败\n") ;
  31.                 exit(EXIT_FAILURE) ;
  32.         }
  33.         password = input_plaintext() ;
  34.         len = strlen(password) ;
  35.         key = create_CipherKey(len) ;   
  36.         fwrite(password, 1, len, fp) ;
  37.         fwrite(key,sizeof(int),len,fp) ;
  38.         fclose(fp) ; // 至此写入明文和密匙,以二进制的形式
  39.         create_BidCirlinklist(&l) ;
  40.         new_password = create_Cipher(l,len,key,password) ;
  41.         printf ("%s\n",password) ;    // 从这里开始便是验证输入和输出结果
  42.         i = 0 ;
  43.         while ( i < len )
  44.         {
  45.                 printf("%2d ",key[i]) ;
  46.                 i++;
  47.         }
  48.         printf("\n") ;
  49.         for( i = 0; i < len ; i++)
  50.         {
  51.                 printf("%c ",new_password[i]) ;  // 单个字母输出并无问题
  52.         }
  53.         printf("\n") ;
  54.         printf("%s\n",new_password) ;  // 问题出现在这个输出上      // 你期望这个printf输出什么内容?
  55.         free(password);         // 少了这个吧?
  56.         free(new_password);
  57.         free(key);
  58.         return 0;
  59. }
  60. // 输入明文
  61. static char* input_plaintext (void)
  62. {
  63. #if 0
  64.         int Len ;
  65.         char *Str ,*str;
  66.         str = (char*)malloc(SIZE) ;     // 永远都不需要乘一个sizeof(char)
  67.         printf ("请输入明文(至多输入16位):") ;
  68.         scanf ("%s",str) ;
  69.         Len = strlen(str) ;
  70.         Str = (char*)malloc(Len + 1) ;  // 这里不需要加1吗?
  71.         strcpy(Str,str) ;
  72.         free(str);          // 这里不需要free吗?
  73.         return Str ;
  74. #endif
  75.         char *str = malloc(5);
  76.         strcpy(str, "abcd");
  77.         return str;
  78. }
  79. // 建立解密环
  80. static void create_BidCirlinklist ( Linklist *L) // L是指针的指针
  81. {
  82.         node *flag , *new_node ;
  83.         int i = 0 ;
  84.         while ( i< 26 )
  85.         {
  86.                 new_node = (node *)malloc(sizeof(node )) ;
  87.                 new_node->elem = 'A'+i ;
  88.                 if ((*L) == NULL )
  89.                 {
  90.                         flag = (*L) = new_node ;
  91.                         flag->next = flag->previous = NULL ;
  92.                 }
  93.                 else
  94.                 {
  95.                         new_node->next = flag->next ;
  96.                         flag->next = new_node ;
  97.                         new_node->previous = flag ;
  98.                         flag = new_node ;
  99.                 }
  100.                 i++ ;
  101.         }
  102.         flag->next = (*L) ;
  103.         (*L)->previous = flag ;
  104. }
  105. // 生成随机密匙
  106. static int * create_CipherKey ( int len )
  107. {
  108.         int i ;
  109.         int *Key = (int *)malloc(sizeof(int) * len) ;
  110.         for( i = 0 ; i < len ; i++)
  111.         {
  112.                 Key[i] = rand()%100 ;
  113.         }
  114.         return Key ;
  115. }

  116. // 生成密文
  117. static Elemtype* create_Cipher (Linklist L, int len , int *key , char * passward)  
  118. {
  119.         int i ;
  120.         Elemtype *new_cipher = (Elemtype*)malloc( sizeof(Elemtype)*len ) ;
  121.         node *flag ;
  122.         for ( i = 0 ; i < len ; i++)
  123.         {
  124.                 flag = find_ch(L , passward[i]) ;
  125.                 create_one_cipher(flag,key[i],&new_cipher[i]) ;
  126.         }
  127.         return new_cipher ;
  128. }

  129. // 找到对应的字母,便于生成新字母
  130. static node* find_ch (Linklist l , Elemtype ch)
  131. {
  132.         node *flag1 = l ;
  133.         if ( ch > 'Z')
  134.         {
  135.                 ch -= 32 ;
  136.         }
  137.         if ( ch <= 'M')
  138.         {
  139.                 while (flag1->elem != ch)
  140.                         flag1 = flag1->next ;
  141.         }
  142.         else
  143.         {
  144.                 while (flag1->elem != ch)
  145.                         flag1 = flag1->previous ;
  146.         }
  147.         return flag1 ;
  148. }

  149. // 生成新一位密文并用ch返回
  150. static void create_one_cipher (node*S , int n , Elemtype *ch)  // 当n的绝对值大于13时 向反方向移动 提高效率
  151. {
  152.     node *flag2 = S ;
  153.     n = n > 0 ? n : -n;
  154.     n %= 26 ;
  155.     while (n--)
  156.         flag2 = flag2->next ;
  157.     *ch = flag2->elem ;
  158. #if 0
  159.     node *flag2 = S ;
  160.     n = n > 0 ? n : -n;
  161.     n %= 26 ;
  162.     if ( n >13)     // 这个if-else可以提高效率?
  163.     {
  164.         while (n--)
  165.             flag2 = flag2->previous;
  166.     }
  167.     else
  168.     {
  169.         while (n--)
  170.             flag2 = flag2->next ;
  171.     }        
  172.     *ch = flag2->elem ;
  173. #endif
  174. #if 0
  175.         node *flag2 = S ;
  176.         if ( n > 0)
  177.         {
  178.                 n %= 26 ;
  179.                 if ( n >13)
  180.                 {
  181.                         while (n--)
  182.                                 flag2 = flag2->previous;
  183.                 }
  184.                 else
  185.                 {
  186.                         while (n--)
  187.                                 flag2 = flag2->next ;
  188.                 }        
  189.         }
  190.         else
  191.         {
  192.                 n %= -26 ;
  193.                 if ( n >13)
  194.                 {
  195.                         //while (n++)   // 确定这里是++ ?
  196.                         while(n--)
  197.                                 flag2 = flag2->previous;
  198.                 }
  199.                 else
  200.                 {
  201.                         //while (n++)   // 还有这里
  202.                         while(n--)
  203.                                 flag2 = flag2->next ;
  204.                 }        
  205.         }
  206.         *ch = flag2->elem ;
  207. #endif
  208. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-1 16:59:02 | 显示全部楼层
本帖最后由 北有樵先生 于 2020-4-1 17:00 编辑


首先十分感谢你能看我的代码并指出问题,也让我注意到了很多问题,但输出还是有问题
比如:
输入:      wangbuliuxing
密匙:      0000000000001(假设是这个,方便讨论)
期望输出:wangbuliuxinh
实际输出:wangbuliuxinh794问日20394

后面粗体意思是所出现的乱码,通过malloc函数分配的空间所存储的字符,再用printf(“%s”)输出时会出现乱码,也就是我第二个输出那里,你问我想做什么,那里是我想与上面通过输出单个字符的结果作比较。根据我自己试下来,当输入字符串长度大于等于8时,通过%s输出会出现乱码,这个也是我一开始的问题
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-1 17:50:36 | 显示全部楼层
北有樵先生 发表于 2020-4-1 16:59
首先十分感谢你能看我的代码并指出问题,也让我注意到了很多问题,但输出还是有问题
比如:
输入:   ...

一组输入输出不具有代表性,我看不出规律
输入g,在密匙为1时输出h,密匙是2时输出什么?是3呢?-1呢?-2?等等
你说长度大于8会出问题,那小于等于8没问题?再举3个例子
小于8不会出问题的
等于8不会出问题的
还有大于8会出问题的

“假设是这个,方便讨论”
最好还是不要这样,这样不方便观察输入与输出的关系
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-1 17:52:50 | 显示全部楼层
为了更好的观察输入输出,你就随便编一个密匙吧,类似于随机
考虑上正数、负数和 0
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-1 18:00:45 | 显示全部楼层
就用这个密匙,在你看来输出什么才对?

  1. ./main
  2. wangbuliuxing
  3. 39 93 42 16 54 77 50 38 61  0 42 15 13
  4. J P D W D T J U D X Y C T
  5. JPDWDTJUDXYCT
复制代码


  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <string.h>


  5. #define OK     1
  6. #define ERROR  0
  7. #define SIZE   16

  8. typedef char Elemtype ;
  9. typedef struct node
  10. {
  11.         Elemtype elem ;
  12.         struct node *next ;
  13.         struct node *previous ;
  14. }node , *Linklist ;

  15. static char* input_plaintext (void) ;
  16. static void create_BidCirlinklist ( Linklist *L) ;
  17. static int * create_CipherKey ( int len ) ;
  18. static node* find_ch (Linklist L , Elemtype ch)  ;
  19. static void create_one_cipher (node*S , int n , Elemtype *ch) ;
  20. static Elemtype* create_Cipher (Linklist L, int len , int *key , char * passward)  ;

  21. int main (void)
  22. {
  23.         FILE *fp ;
  24.         int len , *key , i;
  25.         Elemtype *password , *new_password ;
  26.         Linklist l = NULL;
  27.         srand(time(NULL)) ;     // 放在这里更好
  28.         if ( (fp = fopen("Encrypted.txt", "wb")) == NULL)
  29.         {
  30.                 printf("打开文件失败\n") ;
  31.                 exit(EXIT_FAILURE) ;
  32.         }
  33.         password = input_plaintext() ;
  34.         len = strlen(password) ;
  35.         key = create_CipherKey(len) ;   
  36.         fwrite(password, 1, len, fp) ;
  37.         fwrite(key,sizeof(int),len,fp) ;
  38.         fclose(fp) ; // 至此写入明文和密匙,以二进制的形式
  39.         create_BidCirlinklist(&l) ;
  40.         new_password = create_Cipher(l,len,key,password) ;
  41.         printf ("%s\n",password) ;    // 从这里开始便是验证输入和输出结果
  42.         i = 0 ;
  43.         while ( i < len )
  44.         {
  45.                 printf("%2d ",key[i]) ;
  46.                 i++;
  47.         }
  48.         printf("\n") ;
  49.         for( i = 0; i < len ; i++)
  50.         {
  51.                 printf("%c ",new_password[i]) ;  // 单个字母输出并无问题
  52.         }
  53.         printf("\n") ;
  54.         printf("%s\n",new_password) ;  // 问题出现在这个输出上      // 你期望这个printf输出什么内容?
  55.         free(password);         // 少了这个吧?
  56.         free(new_password);
  57.         free(key);
  58.         return 0;
  59. }
  60. // 输入明文
  61. static char* input_plaintext (void)
  62. {
  63. #if 0
  64.         int Len ;
  65.         char *Str ,*str;
  66.         str = (char*)malloc(SIZE) ;     // 永远都不需要乘一个sizeof(char)
  67.         printf ("请输入明文(至多输入16位):") ;
  68.         scanf ("%s",str) ;
  69.         Len = strlen(str) ;
  70.         Str = (char*)malloc(Len + 1) ;  // 这里不需要加1吗?
  71.         strcpy(Str,str) ;
  72.         free(str);          // 这里不需要free吗?
  73.         return Str ;
  74. #endif
  75.         char *str = malloc(14);
  76.         strcpy(str, "wangbuliuxing");
  77.         return str;
  78. }
  79. // 建立解密环
  80. static void create_BidCirlinklist ( Linklist *L) // L是指针的指针
  81. {
  82.         node *flag , *new_node ;
  83.         int i = 0 ;
  84.         while ( i< 26 )
  85.         {
  86.                 new_node = (node *)malloc(sizeof(node )) ;
  87.                 new_node->elem = 'A'+i ;
  88.                 if ((*L) == NULL )
  89.                 {
  90.                         flag = (*L) = new_node ;
  91.                         flag->next = flag->previous = NULL ;
  92.                 }
  93.                 else
  94.                 {
  95.                         new_node->next = flag->next ;
  96.                         flag->next = new_node ;
  97.                         new_node->previous = flag ;
  98.                         flag = new_node ;
  99.                 }
  100.                 i++ ;
  101.         }
  102.         flag->next = (*L) ;
  103.         (*L)->previous = flag ;
  104. }
  105. // 生成随机密匙
  106. static int * create_CipherKey ( int len )
  107. {
  108.         int i ;
  109.         int *Key = (int *)malloc(sizeof(int) * len) ;
  110.         for( i = 0 ; i < len ; i++)
  111.         {
  112.                 Key[i] = rand()%100 ;
  113.         }
  114.         return Key ;
  115. }

  116. // 生成密文
  117. static Elemtype* create_Cipher (Linklist L, int len , int *key , char * passward)  
  118. {
  119.         int i ;
  120.         Elemtype *new_cipher = (Elemtype*)malloc( sizeof(Elemtype)*len ) ;
  121.         node *flag ;
  122.         for ( i = 0 ; i < len ; i++)
  123.         {
  124.                 flag = find_ch(L , passward[i]) ;
  125.                 create_one_cipher(flag,key[i],&new_cipher[i]) ;
  126.         }
  127.         return new_cipher ;
  128. }

  129. // 找到对应的字母,便于生成新字母
  130. static node* find_ch (Linklist l , Elemtype ch)
  131. {
  132.         node *flag1 = l ;
  133.         if ( ch > 'Z')
  134.         {
  135.                 ch -= 32 ;
  136.         }
  137.         if ( ch <= 'M')
  138.         {
  139.                 while (flag1->elem != ch)
  140.                         flag1 = flag1->next ;
  141.         }
  142.         else
  143.         {
  144.                 while (flag1->elem != ch)
  145.                         flag1 = flag1->previous ;
  146.         }
  147.         return flag1 ;
  148. }

  149. // 生成新一位密文并用ch返回
  150. static void create_one_cipher (node*S , int n , Elemtype *ch)  // 当n的绝对值大于13时 向反方向移动 提高效率
  151. {
  152.     node *flag2 = S ;
  153.     n = n > 0 ? n : -n;
  154.     n %= 26 ;
  155.     while (n--)
  156.         flag2 = flag2->next ;
  157.     *ch = flag2->elem ;
  158. #if 0
  159.     node *flag2 = S ;
  160.     n = n > 0 ? n : -n;
  161.     n %= 26 ;
  162.     if ( n >13)     // 这个if-else可以提高效率?
  163.     {
  164.         while (n--)
  165.             flag2 = flag2->previous;
  166.     }
  167.     else
  168.     {
  169.         while (n--)
  170.             flag2 = flag2->next ;
  171.     }        
  172.     *ch = flag2->elem ;
  173. #endif
  174. #if 0
  175.         node *flag2 = S ;
  176.         if ( n > 0)
  177.         {
  178.                 n %= 26 ;
  179.                 if ( n >13)
  180.                 {
  181.                         while (n--)
  182.                                 flag2 = flag2->previous;
  183.                 }
  184.                 else
  185.                 {
  186.                         while (n--)
  187.                                 flag2 = flag2->next ;
  188.                 }        
  189.         }
  190.         else
  191.         {
  192.                 n %= -26 ;
  193.                 if ( n >13)
  194.                 {
  195.                         //while (n++)   // 确定这里是++ ?
  196.                         while(n--)
  197.                                 flag2 = flag2->previous;
  198.                 }
  199.                 else
  200.                 {
  201.                         //while (n++)   // 还有这里
  202.                         while(n--)
  203.                                 flag2 = flag2->next ;
  204.                 }        
  205.         }
  206.         *ch = flag2->elem ;
  207. #endif
  208. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2020-4-1 18:50:19 | 显示全部楼层
本帖最后由 北有樵先生 于 2020-4-1 18:57 编辑
人造人 发表于 2020-4-1 18:00
就用这个密匙,在你看来输出什么才对?


我用的dev c++ 5.11,我复制你的代码然后运行,在正确结果后会出现乱码,会是编译器的问题嘛
因为我权限不够,没法给你发图片,要不先放着,然后我权限够了再说?

                               
登录/注册后可看大图

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-1 19:29:48 | 显示全部楼层
北有樵先生 发表于 2020-4-1 18:50
我用的dev c++ 5.11,我复制你的代码然后运行,在正确结果后会出现乱码,会是编译器的问题嘛
因为我权 ...

图片显示不出来
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-2 10:36:06 | 显示全部楼层

那我先等到我有权限了吧
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-2 13:12:27 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-3 21:13:32 | 显示全部楼层
人造人 发表于 2020-4-2 13:12
https://fishc.com.cn/forum.php?mod=viewthread&tid=155962&highlight=%B7%A2%CD%BC%C6%AC

https://imgchr.com/i/GJvEaq
https://imgchr.com/i/GJvVI0

审核把回复删了,现在重发,第二个图就出现了乱码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-21 14:53

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表