Last active
October 24, 2024 00:43
-
-
Save Mroik/9fd91bc1fa978c14e48b1499664ea39a to your computer and use it in GitHub Desktop.
Expected output `Y2lhbyBjb21lIHN0YWk/`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdbool.h> | |
#include <string.h> | |
void encode(unsigned char data[21]) | |
{ | |
unsigned char base[15]; | |
memcpy(base, data, 15); | |
for(int x = 0; x < 20; x++) { | |
unsigned char temp = 0b11111100; | |
temp &= base[0]; | |
temp = temp >> 2; | |
if(temp < 26) { | |
data[x] = temp + 'A'; | |
} else if(temp >= 26 && temp <= 51) { | |
data[x] = temp - 26 + 'a'; | |
} else if(temp >= 52 && temp <= 61) { | |
data[x] = temp - 52 + '0'; | |
} else if(temp == 62) { | |
data[x] = '+'; | |
} else if(temp == 63) { | |
data[x] = '/'; | |
} | |
// Shift everything left | |
for(int y = 0; y < 14; y++) { | |
base[y] = base[y] << 6; | |
temp = 0b11111100; | |
temp &= base[y + 1]; | |
temp = temp >> 2; | |
base[y] |= temp; | |
} | |
base[14] = base[14] << 6; | |
} | |
data[20] = '\0'; | |
} | |
int main() | |
{ | |
unsigned char data[21] = "ciao come stai?"; | |
encode(data); | |
printf("%s\n", data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment