#include
#include
#include
#include
#include
#include
#define MAX_STR 256
int b64_distance(char str1[MAX_STR], char str2[MAX_STR]){
char newStr1[MAX_STR];
char newStr2[MAX_STR];
int b64_1[6];
int b64_2[6];
char arr1[6];
char arr2[6];
memset(newStr1, 0, sizeof(newStr1));
memset(newStr2, 0, sizeof(newStr2));
memset(b64_1, 0, sizeof(b64_1));
memset(b64_2, 0, sizeof(b64_2));
int newStr1_len = removeNonBase64(str1, newStr1);
int newStr2_len = removeNonBase64(str2, newStr2);
//take only the relevant part of the arrey
relevantPart (newStr1, arr1, newStr1_len);
relevantPart (newStr2, arr2, newStr2_len);
//convert to base64
// convertTob64(arr1, b64_1);
// convertTob64(arr2, b64_2);
//convert to decimal
int num1 = b64ToDecimal(b64_1);
int num2 = b64ToDecimal(b64_2);
return num1 - num2;
}
int removeNonBase64 (char *src, char *dest)
{
int src_len = strlen(src);
int dest_len = 0;
for(int i = 0; i < src_len; i++){
if('A' <= src[i] && src[i] <= 'Z'){
dest[dest_len] = src[i] - 'A';
dest_len++;
}
else if('a' <= src[i] && src[i] <= 'z'){
dest[dest_len] = src[i] -'a' + 26;
dest_len++;
}
else if('0' <= src[i] && src[i] <= '9'){
dest[dest_len] = src[i] -'0' + 52;
dest_len++;
}
else if(src[i] == '+'){
dest[dest_len] = src[i] + 62;
dest_len++;
}
else if(src[i] == '/'){
dest[dest_len] = src[i] + 63;
dest_len++;
}
}
return dest_len;
}
void relevantPart (char *src, char dest[6], int src_len)
{
if(src_len >= 6)
{
for(int i = 0; i < 6 ; i++)
{
dest[6 - i] = src[src_len - i];
}
}
else
{
int i;
for(i = 0; i < src_len ; i++)
{
dest[6 - i] = src[src_len - i];
}
for(; i < 6 ; i++)
{
dest[6 - i] = 'A';
}
}
return;
}
void convertTob64()
{
//a-z
//A-Z
//0-9
//+
// /
}
int b64ToDecimal (int* arr)
{
int temp[4];
for(int i = 5; i < 2; i--)
{
temp[i] = pow(64, i);
}
_m128i xmm1 = _mm_lddqu_si128((_m128i *)arr);
_m128i xmm2 = _mm_lddqu_si128((_m128i *)temp);
__m128i resultxmm = _mm_mul_epi32(xmm1, xmm2);
int horiz 0) +
_mm_extract_epi32(resultxmm, 1) +
_mm_extract_epi32(resultxmm, 2) +
_mm_extract_epi32(resultxmm, 3) +
(arr[4] * 64) +
arr[5];
return horizontal_sum;
}
uint16_t getBitPattern(char c[16]){
__m128i ranges = _mm_set_epi8(0, 0, 0, 0, 0, 0, '/', '/', '+', '+', 'z', 'a', '9', '0', 'Z', 'A');
_m128i chars = _mm_lddqu_si128((_m128i *)c);
__m128i result = _mm_cmpistrm(ranges, chars, _SIDD_UBYTE_OPS | _SIDD_CMP_RANGES | _SIDD_BIT_MASK);
uint16_t intResults = _mm_extract_epi16(result, 0);
return intResults;
}