sophuwu.site > otpp
made some simple secret with encoding thingy
sophuwu sophie@sophuwu.site
Fri, 06 Oct 2023 07:27:36 +0200
commit

3fd1c51f3a378d1750bbc0e3a05d40aee5f04deb

2 files changed, 44 insertions(+), 0 deletions(-)

jump to
A .gitignore

@@ -0,0 +1,2 @@

+.idea +a.out
A main.cpp

@@ -0,0 +1,42 @@

+#include <fstream> + +const char* chars16 = "0123456789ABCDEF"; + +struct secret { + char bytes[16]; + + void load(char* file) { + FILE* f = fopen(file, "r"); + fread(secret, 1, 16, f); + fclose(f); + } + + void save(char* file) { + FILE* f = fopen(file, "w"); + fwrite(secret, 1, 16, f); + fclose(f); + } + + void generate() { + int r, i, j; + for (i = 0; i < 16; i += 4) { + r = rand(); + for (j = 0; j < 4; j++) { + bytes[i + j] = r & 255; + r >>= 8; + } + } + } +}; + +stuct otp { + +}; + +int main() { + secret s; + s.generate(); + for (int i = 0; i < 16; i++) { + printf("%c%c", chars16[s.bytes[i] >> 4], chars16[s.bytes[i] & 15]); + } +}