Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstring>
- unsigned char rom[0x1000000];
- // 0123456789ABCDEF6789012
- char str[] = "abcdefghtijklmnoprsuqvw";
- int convert(int a)
- {
- int r = 0;
- for (int i=0; i<23; ++i)
- {
- if (a&(1<<(strchr(str,'a'+i)-str)))
- r|=(1<<i);
- }
- return r;
- }
- int convert2(int a)
- {
- int r = 0;
- for (int i=0; i<23; ++i)
- {
- if (a&(1<<i))
- r|=(1<<(strchr(str,'a'+i)-str));
- }
- return r;
- }
- int main(int argc, char **args)
- {
- if (argc != 4)
- {
- printf("gopher_bitswap.exe from|to input output");
- return 0;
- }
- FILE *f = fopen(args[2],"rb");
- if (!f)
- return 0;
- fread(rom,1,sizeof(rom),f);
- fclose(f);
- f = fopen(args[3],"wb");
- if (!f)
- return 0;
- bool from = true;
- if (!strcmp(args[1],"to"))
- from = false;
- for (int i=0; i<sizeof(rom); ++i)
- {
- int idx = (from?convert(i>>1):convert2(i>>1));
- unsigned char q = rom[(idx<<1)|(i&1)];
- fwrite(&q,1,1,f);
- }
- fclose(f);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement