Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ** xor.c for xor in /home/boulogne_q/Files/Elcrypt/sources/fonctions
- **
- ** Made by quentin boulogne
- ** Login <boulogne_q@epitech.net>
- **
- ** Started on Sat Feb 28 06:45:12 2015 quentin boulogne
- ** Last update Sat Feb 28 14:53:01 2015 quentin boulogne
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "Elcrypt.h"
- char *rotate_key(char *str) //-- Fonction qui décale les bits vers la gauche 4 par 4 -> ex: 1011 1100 0110 donnera 1100 011\
- 0 1011 --//
- {
- int i;
- int j;
- char *save;
- char *result;
- //printf("Begin : %s\n", str);
- result = malloc(sizeof(char) * 4096 * 99999);
- save = malloc(sizeof(char) * 4);
- i = 0;
- j = 0;
- while (i <= 3)
- save[i] = str[i++];
- i = 4;
- while (str[i])
- {
- result[j] = str[i];
- j++;
- i++;
- }
- i = 0;
- while (save[i])
- {
- result[j] = save[i];
- j++;
- i++;
- }
- return (result);
- }
- int digit_to_int(char d)
- {
- char str[2];
- str[0] = d;
- str[1] = '\0';
- return (int) strtol(str, NULL, 10);
- }
- int bitXor(int x, int y) //-- XOR ENTRE DEUX BITS --//
- {
- int a = x & y;
- int b = ~x & ~y;
- int z = ~a & ~b;
- return (z);
- }
- )
- {
- result[i] = 48 + bitXor(digit_to_int(str3[i]), digit_to_int(str2[i]));
- i++;
- }
- }
- if (strlen(str2) < strlen(str1))
- {
- j = (strlen(str1) - strlen(str2)) - 1;
- while (i <= j)
- str3[i++] = '0';
- while (str2[k])
- str3[i++] = str2[k++];
- i = 0;
- while (str1[i])
- {
- result[i] = 48 + bitXor(digit_to_int(str3[i]), digit_to_int(str1[i]));
- i++;
- }
- }
- if (strlen(str1) == strlen(str2))
- {
- i = 0;
- while (str1[i])
- {
- result[i] = 48 + bitXor(digit_to_int(str2[i]), digit_to_int(str1[i]));
- i++;
- }
- }
- return (result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement