Advertisement
Guest User

Untitled

a guest
Feb 28th, 2015
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. /*
  2. ** xor.c for xor in /home/boulogne_q/Files/Elcrypt/sources/fonctions
  3. **
  4. ** Made by quentin boulogne
  5. ** Login <boulogne_q@epitech.net>
  6. **
  7. ** Started on Sat Feb 28 06:45:12 2015 quentin boulogne
  8. ** Last update Sat Feb 28 14:53:01 2015 quentin boulogne
  9. */
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include "Elcrypt.h"
  15.  
  16. char *rotate_key(char *str) //-- Fonction qui décale les bits vers la gauche 4 par 4 -> ex: 1011 1100 0110 donnera 1100 011\
  17. 0 1011 --//
  18. {
  19. int i;
  20. int j;
  21. char *save;
  22. char *result;
  23.  
  24. //printf("Begin : %s\n", str);
  25. result = malloc(sizeof(char) * 4096 * 99999);
  26. save = malloc(sizeof(char) * 4);
  27. i = 0;
  28. j = 0;
  29. while (i <= 3)
  30. save[i] = str[i++];
  31. i = 4;
  32. while (str[i])
  33. {
  34. result[j] = str[i];
  35. j++;
  36. i++;
  37. }
  38. i = 0;
  39. while (save[i])
  40. {
  41. result[j] = save[i];
  42. j++;
  43. i++;
  44. }
  45. return (result);
  46. }
  47.  
  48. int digit_to_int(char d)
  49. {
  50. char str[2];
  51.  
  52. str[0] = d;
  53. str[1] = '\0';
  54. return (int) strtol(str, NULL, 10);
  55. }
  56.  
  57. int bitXor(int x, int y) //-- XOR ENTRE DEUX BITS --//
  58. {
  59. int a = x & y;
  60. int b = ~x & ~y;
  61. int z = ~a & ~b;
  62.  
  63. return (z);
  64. }
  65.  
  66. )
  67. {
  68. result[i] = 48 + bitXor(digit_to_int(str3[i]), digit_to_int(str2[i]));
  69. i++;
  70. }
  71. }
  72. if (strlen(str2) < strlen(str1))
  73. {
  74. j = (strlen(str1) - strlen(str2)) - 1;
  75. while (i <= j)
  76. str3[i++] = '0';
  77. while (str2[k])
  78. str3[i++] = str2[k++];
  79. i = 0;
  80. while (str1[i])
  81. {
  82. result[i] = 48 + bitXor(digit_to_int(str3[i]), digit_to_int(str1[i]));
  83. i++;
  84. }
  85. }
  86. if (strlen(str1) == strlen(str2))
  87. {
  88. i = 0;
  89. while (str1[i])
  90. {
  91. result[i] = 48 + bitXor(digit_to_int(str2[i]), digit_to_int(str1[i]));
  92. i++;
  93. }
  94. }
  95. return (result);
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement