Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // kamila szewczyk, 2020
- #include <stdlib.h>
- #include <stdio.h>
- #include <stdint.h>
- const uint8_t * xlat1 = "+b(29e*j1VMEKLyC})8&m#~W>qxdRp0wkrUo[D7,X"
- "TcA\"lI.v%{gJh4G\\-=O@5`_3i<?Z';FNQuY]szf$!BS/|t:Pn6^Ha";
- uint8_t assembly(uint8_t c) {
- switch(c) {
- case 'i': return 4;
- case '<': return 5;
- case '/': return 23;
- case '*': return 39;
- case 'j': return 40;
- case 'p': return 62;
- case 'o': return 68;
- case 'v': return 81;
- }
- fprintf(stderr, "invalid character: %d (%c)\n", c, c);
- }
- uint8_t decodeInt(uint8_t code, uint64_t position) {
- return xlat1[(((uint64_t) code) - 33ull + position) % 94];
- }
- void normalize(void) {
- uint64_t t = 0; int8_t ct;
- while((ct = getchar()) != EOF) {
- if(ct > 32)
- putchar(decodeInt(ct, t));
- t++;
- }
- }
- uint8_t encodeInt(uint64_t code, uint64_t position) {
- int8_t t = (code - position % 94 + 94) % 94;
- if(t < 33)
- t += 94;
- return t;
- }
- void assemble(void) {
- uint64_t t = 0; int8_t ct;
- while((ct = getchar()) != EOF) {
- if(ct > 32)
- putchar(encodeInt(assembly(ct), t));
- t++;
- }
- }
- int main(int argc, char * argv[]) {
- if(argv[1][0] == 'e')
- assemble();
- else if(argv[1][0] == 'd')
- normalize();
- }
Advertisement
Add Comment
Please, Sign In to add comment