Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ** encrypt.c for encrypt in /home/boulogne_q/Files/Elcrypt/sources/fonctions
- **
- ** Made by quentin boulogne
- ** Login <boulogne_q@epitech.net>
- **
- ** Started on Sat Feb 28 02:43:11 2015 quentin boulogne
- ** Last update Sat Feb 28 15:07:46 2015 quentin boulogne
- */
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include "Elcrypt.h"
- char *substract_LSB(char *prim_key_64)
- {
- char *prim_key_56;
- int i;
- int j;
- int k;
- prim_key_56 = malloc(sizeof(char) * 57);
- k = 0;
- j = 0;
- i = 0;
- while (i < 64)
- {
- while (k != 7)
- {
- prim_key_56[j] = prim_key_64[i];
- i++;
- j++;
- k++;
- }
- i++;
- k = 0;
- }
- return (prim_key_56);
- }
- char *convertBaseVersion(char input, int base, int digits)
- {
- int i;
- int remainder;
- char digitsArray[17] = "0123456789ABCDEF";
- char *output;
- output = malloc(sizeof(char) * 4096);
- i = digits;
- while (i > 0)
- {
- remainder = input % base;
- input = input / base;
- output[i - 1] = digitsArray[remainder];
- i--;
- }
- output[digits] = '\0';
- return (output);
- }
- char *str_2_bin(char *str)
- {
- char *ascii_2_bin;
- int i;
- i = 0;
- ascii_2_bin = malloc(sizeof(char) * 4096 * 999999);
- while (str[i])
- {
- strcat(ascii_2_bin, convertBaseVersion(str[i], 2, 8));
- i++;
- }
- return (ascii_2_bin);
- // printf("%s\n", ascii_2_bin);
- }
- int check_bloc_len(char *str)
- {
- int i;
- i = 0;
- while (str[i] != '\0')
- i++;
- if (i == 64) //-- if bloc size = 64, return 1 --//
- return (1);
- else if (i / 64 == 0) //-- if bloc size if multiple of 64, return 2 --//
- return (2);
- else if (i / 64 != 0) //-- if bloc size if not a multiple of 64, return 3 --//
- return (3);
- }
- char *get_first_half_bin_word(char *str)
- {
- int i;
- char *first_half_binword;
- first_half_binword = malloc(sizeof(char) * 65);
- i = 0;
- while (i <= 31)
- {
- first_half_binword[i] = str[i];
- i++;
- }
- first_half_binword[i] = '\0';
- return (first_half_binword);
- }
- char *get_32_last_bit(char *str)
- {
- int i;
- int k;
- int j;
- char *result;
- i = 0;
- result = malloc(sizeof(char) * 4096 * 99999);
- k = strlen(str);
- j = k - 32;
- while (str[j])
- {
- result[i] = str[j];
- i++;
- j++;
- }
- return (result);
- }
- int reseau_festel(char *str, char *key)
- {
- int i;
- char *key_rotate;
- char *groupe_1;
- char *groupe_2;
- char *first_half_binword;
- char *second_half_binword;
- key_rotate = malloc(sizeof(char) * 4096 * 99999);
- groupe_1 = malloc(sizeof(char) * 4096 * 99999);
- groupe_2 = malloc(sizeof(char) * 4096 * 99999);
- printf("~~~ Clé 56bits : %s \n", key);
- key = rotate_key(key);
- printf("~~~ Clé 56bits rotate avec N = 1 : %s \n", key);
- key = get_32_last_bit(key);
- printf("~~~ Clé 56bits rotate (32 last bits) : %s\n", key);
- first_half_binword = get_first_half_bin_word(str);
- second_half_binword = get_second_half_bin_word(str);
- printf("~~~ Debut : \n~~~G1 : %s\n~~~ G2 : %s\n", first_half_binword, second_half_binword);
- groupe_2 = xor(key, first_half_binword);
- printf("~~~ Resultat : \n~~~ Gauche : %s\n~~~~ Droite : %s\n", second_half_binword, groupe_2);
- }
- int encrypt_64(char *str, char *key)
- {
- char *first_half_binword;
- char *second_half_binword;
- first_half_binword = get_first_half_bin_word(str);
- second_half_binword = get_second_half_bin_word(str);
- reseau_festel(str, key);
- }
- int do_encrypt(char *str, char *key)
- {
- char *bin_word;
- int bloc_type;
- bin_word = malloc(sizeof(char) * 4096 * 9999);
- bin_word = str_2_bin(str); //-- First step : Put Ascii To Binary -- //
- bloc_type = check_bloc_len(bin_word); //-- Second step : Check bin len --//
- key = substract_LSB(key); //-- Third ste : Key Without Least Significant Bit --//
- //printf("KEY = %s\n", key);
- bloc_type == 1 ? encrypt_64(bin_word, key) : 0;
- // bloc_type == 2 ? encrypt_m64(bin_word) : 0;
- //bloc_type == 3 ? encrypt_nm64(bin_word) : 0;
- }
- int main()
- {
- char Text[] = "Speciaux";
- char key[] = "0101010101010101010101010101010101010101010101010101010101010101";
- do_encrypt(Text, key);
- }
- -UUU:**--F1 encrypt.c Bot L206 (C/l Abbrev) ---------------------------------------------------------------------------------------
- End of buffer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement