flat integer
This commit is contained in:
parent
6475baa50e
commit
af51f4198c
9 changed files with 128 additions and 5 deletions
|
@ -1,7 +1,10 @@
|
|||
#include "base64.hpp"
|
||||
|
||||
#define B64_IGNORE 0xFE
|
||||
#define B64_PADDING 0xFF
|
||||
|
||||
std::string sosc::cgc::base64_encode(const std::string& data) {
|
||||
return base64_decode(data.c_str());
|
||||
return base64_encode(data.c_str(), data.length());
|
||||
}
|
||||
|
||||
std::string sosc::cgc::base64_encode(const void* raw, size_t length) {
|
||||
|
@ -32,6 +35,60 @@ std::string sosc::cgc::base64_encode(const void* raw, size_t length) {
|
|||
return encoded;
|
||||
}
|
||||
|
||||
std::string base64_decode(const std::string& data) {
|
||||
|
||||
static uint8_t base64_decode_char(char c) {
|
||||
if(c >= 'A' && c <= 'Z')
|
||||
return c - 'A';
|
||||
else if(c >= 'a' && c <= 'z')
|
||||
return c - 'a' + 26;
|
||||
else if(c >= '0' && c <= '9')
|
||||
return c - '0' + 52;
|
||||
else if(c == '+')
|
||||
return 62;
|
||||
else if(c == '/')
|
||||
return 63;
|
||||
else if(c == '=')
|
||||
return B64_PADDING;
|
||||
else
|
||||
return B64_IGNORE;
|
||||
}
|
||||
|
||||
static void base64_decode_append(std::string* decoded, int data) {
|
||||
*decoded += (char)(data >> 16);
|
||||
|
||||
if((data & (1 << 30)) == 0)
|
||||
*decoded += (char)(data >> 8);
|
||||
|
||||
if((data & (1 << 29)) == 0)
|
||||
*decoded += (char)data;
|
||||
}
|
||||
|
||||
std::string sosc::cgc::base64_decode(const std::string& data) {
|
||||
std::string decoded;
|
||||
int index = 0, j = 0;
|
||||
|
||||
for(std::string::size_type i = 0; i < data.length(); ++i) {
|
||||
int sextet = base64_decode_char(data[i]);
|
||||
|
||||
if(sextet == B64_IGNORE || sextet == B64_PADDING) {
|
||||
if(sextet == B64_PADDING && i >= data.length() - 2 && j > 1)
|
||||
index |= 1 << (31 - j + 1);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
index |= sextet << (6 * (3 - j));
|
||||
|
||||
j = (j + 1) % 4;
|
||||
if(j == 0) {
|
||||
base64_decode_append(&decoded, index);
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(j > 1) {
|
||||
index |= (j == 2) ? 3 << 29 : 1 << 29;
|
||||
base64_decode_append(&decoded, index);
|
||||
}
|
||||
|
||||
return decoded;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#ifndef SOSC_CRYPTO_BASE64
|
||||
#define SOSC_CRYPTO_BASE64
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
namespace sosc {
|
||||
namespace cgc {
|
||||
|
|
1
server/src/crypto/cipher.cpp
Normal file
1
server/src/crypto/cipher.cpp
Normal file
|
@ -0,0 +1 @@
|
|||
#include "cipher.hpp"
|
14
server/src/crypto/cipher.hpp
Normal file
14
server/src/crypto/cipher.hpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef SOSC_CRYPTO_CIPHER_H
|
||||
#define SOSC_CRYPTO_CIPHER_H
|
||||
|
||||
namespace sosc {
|
||||
namespace cgc {
|
||||
class Cipher {
|
||||
public:
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
}}
|
||||
|
||||
#endif
|
2
server/src/crypto/keyex.cpp
Normal file
2
server/src/crypto/keyex.cpp
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "keyex.hpp"
|
||||
|
16
server/src/crypto/keyex.hpp
Normal file
16
server/src/crypto/keyex.hpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef SOSC_CRYPTO_KEYEX_H
|
||||
#define SOSC_CRYPTO_KEYEX_H
|
||||
|
||||
namespace sosc {
|
||||
namespace cgc {
|
||||
class KeyExchange {
|
||||
public:
|
||||
const int key_size = 512;
|
||||
const int key_size_bytes = key_size / 8;
|
||||
const int generator = 2;
|
||||
private:
|
||||
|
||||
};
|
||||
}}
|
||||
|
||||
#endif
|
|
@ -32,7 +32,5 @@ int main(int argc, char **argv) {
|
|||
|
||||
//std::string a = sosc::cgc::sha1("test", true);
|
||||
|
||||
std::cout << sosc::cgc::base64_encode("this is a longer test");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
1
server/src/utils/bigint.cpp
Normal file
1
server/src/utils/bigint.cpp
Normal file
|
@ -0,0 +1 @@
|
|||
#include "bigint.hpp"
|
32
server/src/utils/bigint.hpp
Normal file
32
server/src/utils/bigint.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#ifndef SOSC_UTIL_BIGINT_H
|
||||
#define SOSC_UTIL_BIGINT_H
|
||||
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
namespace sosc {
|
||||
class BigInteger {
|
||||
public:
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> value;
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
FFFFFF
|
||||
FFFF x
|
||||
========
|
||||
FE01
|
||||
FE0100
|
||||
FE010000 +
|
||||
==========
|
||||
FEFFFF01
|
||||
FE0100
|
||||
FE010000
|
||||
FE01000000 +
|
||||
============
|
||||
FFFEFF0001
|
||||
*/
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue