Commit 4507457d authored by Marek Gera's avatar Marek Gera
Browse files

Update bmp.c

parent c85a9ff5
......@@ -11,38 +11,38 @@ unsigned char* bit_encrypt(const char* text){
unsigned char* desttext = (unsigned char*)calloc(strlen(text)+1,sizeof(char));
strcpy(desttext, text);
// prepisanie znaku do dvojkovej sustavy
int z=0;
int current_character=0;
do{
int new[8]={0};
char new1_tmp;
char tmp=text[z];
int binary[8]={0};
char binary_tmp;
char tmp=text[current_character];
int j=0;
do{
new1_tmp=tmp%2;
new[j]=(int)new1_tmp;
binary_tmp=tmp%2;
binary[j]=(int)binary_tmp;
tmp=tmp/2;
j++;
}while((int)tmp!=0);
for(int i=0;i<4;i++){
int o=new[i];
new[i]=new[7-i];
new[7-i]=o;
int o=binary[i];
binary[i]=binary[7-i];
binary[7-i]=o;
}
// prehodenie prvej stvorice
int o=new[0];
new[0]=new[1];
new[1]=o;
int o1=new[2];
new[2]=new[3];
new[3]=o1;
int o=binary[0];
binary[0]=binary[1];
binary[1]=o;
int o1=binary[2];
binary[2]=binary[3];
binary[3]=o1;
// prehodenie druhej stvorice
int q=0;
for(int i=4;i<8;i++){
if(new[i]==new[q])
new[i]=0;
if(binary[i]==binary[q])
binary[i]=0;
else{
new[i]=1;
binary[i]=1;
}
q++;
}
......@@ -50,12 +50,12 @@ unsigned char* bit_encrypt(const char* text){
int super=0;
for(int i=0;i<8;i++){
int mocnina=pow(2, 7-i);
super=super+new[i]*mocnina;
super=super+binary[i]*mocnina;
}
desttext[z]=super;
z++;
}while(z<strlen(text));
desttext[current_character]=super;
current_character++;
}while(current_character<strlen(text));
return desttext;
}
......@@ -63,16 +63,16 @@ unsigned char* bit_encrypt(const char* text){
char* bit_decrypt(const unsigned char* text){
if(text==NULL || strlen(text)==0)
return NULL;
char* pole = (char*)calloc(strlen((char*)text)+1,sizeof(char));
int z=0;
char* decrypted_array = (char*)calloc(strlen((char*)text)+1,sizeof(char));
int current_character=0;
do{
int new[8]={0};
char new1_tmp;
char tmp=text[z];
int binary[8]={0};
char binary_tmp;
char tmp=text[current_character];
int j=0;
do{
new1_tmp=tmp%2;
new[j]=(int)new1_tmp;
binary[j]=(int)binary_tmp;
tmp=tmp/2;
j++;
}while((int)tmp!=0);
......@@ -80,29 +80,29 @@ do{
// robimm XOR opacne
int q=0;
for(int j=4;j<8;j++){
if(new[q]==new[j]){
new[j]=0;
if(binary[q]==binary[j]){
binary[j]=0;
}
else{
new[j]=1;
binary[j]=1;
}
q++;
}
// prehodenie prvej stvorice
int o=new[0]; new[0]=new[1]; new[1]=o;
int o1=new[2]; new[2]=new[3]; new[3]=o1;
int o=binary[0]; binary[0]=binary[1]; binary[1]=o;
int o1=binary[2]; binary[2]=binary[3]; binary[3]=o1;
// vypocitanie hodnoty
int super=0;
for(int i=0;i<8;i++){
int mocnina=pow(2, 7-i);
super=super+new[i]*mocnina;
super=super+binary[i]*mocnina;
}
pole[z]=(char)super;
decrypted_array[z]=(char)super;
z++;
}while(z<strlen((char*)text));
pole[strlen((char*)text)]='\0';
return pole;
}while(current_character<strlen((char*)text));
decrypted_array[strlen((char*)text)]='\0';
return decrypted_array;
}
unsigned char* bmp_encrypt(const char* key, const char* text){
......@@ -129,10 +129,10 @@ char* bmp_decrypt(const char* key, const unsigned char* text){
if(!isalpha(key[i]))
return NULL;
}
unsigned char* text1=(unsigned char*)text;
char* help = (char*)calloc(strlen((char*)text1)+1,sizeof(char));
unsigned char* unsigned_text=(unsigned char*)text;
char* result = (char*)calloc(strlen((char*)unsigned_text)+1,sizeof(char));
return help;
return result;
}
char* reverse(const char* text){
......@@ -140,20 +140,20 @@ char* reverse(const char* text){
return NULL;
}
int len=(int)strlen(text);
char* help = (char*)calloc(strlen(text)+1,sizeof(char));
char* result = (char*)calloc(strlen(text)+1,sizeof(char));
for(int i=0;i<len;i++){
help[i] = (char)toupper(text[i]);
result[i] = (char)toupper(text[i]);
}
for(int j=0; j<len/2; j++){
char tmp=help[j];
help[j]=help[len-j-1];
help[len-j-1]=tmp;
char tmp=result[j];
result[j]=result[len-j-1];
result[len-j-1]=tmp;
}
help[len]='\0';
result[len]='\0';
return help;
return result;
}
char* vigenere_encrypt(const char* key, const char* text){
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment