Skip to content

Instantly share code, notes, and snippets.

@zao

zao/foo.cc Secret

Created May 19, 2017 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zao/21b00d856012d3f3dafa98fcd9bf3351 to your computer and use it in GitHub Desktop.
Save zao/21b00d856012d3f3dafa98fcd9bf3351 to your computer and use it in GitHub Desktop.
#include <gmp.h>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <string.h>
int main() {
char const* num_txt = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
mpz_t val;
mpz_init_set_str(val, num_txt, 10);
size_t word_count = 0;
void* blob = mpz_export(nullptr, &word_count, 32, 1, -1, 0, val);
printf("%d 32-bit LE words, most significant first, sign %d:", word_count, mpz_sgn(val));
char* p = (char*)blob;
for (size_t i = 0; i < word_count; ++i) {
uint32_t v;
memcpy(&v, p, sizeof(uint32_t));
printf(" 0x%08x", v);
p += sizeof(uint32_t);
}
printf("\n");
free(blob);
mpz_clear(val);
}
$ g++ -o foo foo.cc -lgmp && ./foo
54 32-bit LE words, most significant first, sign 1: 0x62317f1c 0x044e64f6 0xa2f1396b 0xc2cc604d 0xe9897ef2 0x9d8162a2 0xec9fb498 0xead8fc23 0x53f33024 0x3d245669 0x7bef6111 0xcfac4bf1 0x3fce96f1 0x0000d20a 0x00000411 0x00000000 0x33203435 0x69622d32 0x454c2074 0x726f7720 0x202c7364 0x74736f6d 0x67697320 0x6966696e 0x746e6163 0x72696620 0x202c7473 0x6e676973 0x203a3120 0x32367830 0x66373133 0x30206331 0x34343078 0x66343665 0x78302036 0x31663261 0x62363933 0x63783020 0x36636332 0x20643430 0x39657830 0x65373938 0x30203266 0x38643978 0x61323631 0x78302032 0x66396365 0x38393462 0x65783020 0x66386461 0x20333263 0x33357830 0x30333366 0x30203432
root@rpi2:~ # clang++ -o foo foo.cc -I/usr/local/include -L/usr/local/lib -lgmp && ./foo
54 32-bit LE words, most significant first, sign 1: 0x62317f1c 0x044e64f6 0xa2f1396b 0xc2cc604d 0xe9897ef2 0x9d8162a2 0xec9fb498 0xead8fc23 0x53f33024 0x3d245669 0x7bef6111 0xcfac4bf1 0x3fce96f1 0x0000d20a 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment