Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsigned char* bit_encrypt(const char* text){
- unsigned char *dec = calloc(strlen(text)+1, sizeof *text);
- for(int i = 0; i < strlen(text); i++){
- int znak = text[i];
- //
- printf("%d\n", (int)text[i] );
- //
- int bin[] = {0,0,0,0,0,0,0,0};
- //128 64 32 16 8 4 2 1
- for(int j = 0; j < 8; j++){
- if(znak >= 128){
- znak -= 128;
- bin[0] = 1;
- } else if(znak >= 64){
- znak -= 64;
- bin[1] = 1;
- } else if(znak >= 32){
- znak -= 32;
- bin[2] = 1;
- } else if(znak >= 16){
- znak -= 16;
- bin[3] = 1;
- } else if(znak >= 8){
- znak -= 8;
- bin[4] = 1;
- } else if(znak >= 4){
- znak -= 4;
- bin[5] = 1;
- } else if(znak >= 2){
- znak -= 2;
- bin[6] = 1;
- } else if(znak >= 1){
- znak -= 1;
- bin[7] = 1;
- }
- }
- int fbin[2][4];
- fbin[0][0] = bin[1];
- fbin[0][1] = bin[0];
- fbin[0][2] = bin[3];
- fbin[0][3] = bin[2];
- fbin[1][0] = bin[4] ^ fbin[0][0];
- fbin[1][1] = bin[5] ^ fbin[0][1];
- fbin[1][2] = bin[6] ^ fbin[0][2];
- fbin[1][3] = bin[7] ^ fbin[0][3];
- int temp = 0;
- if(fbin[0][0] == 1){
- temp+=128;
- }
- if(fbin[0][1] == 1){
- temp+=64;
- }
- if(fbin[0][2] == 1){
- temp+=32;
- }
- if(fbin[0][3] == 1){
- temp+=16;
- }
- if(fbin[1][0] == 1){
- temp+=8;
- }
- if(fbin[1][1] == 1){
- temp+=4;
- }
- if(fbin[1][2] == 1){
- temp+=2;
- }
- if(fbin[1][3] == 1){
- temp+=1;
- }
- dec[i] = (char)temp;
- }
- return dec;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement