All pastes #773307 Raw Edit

Jemand

public text v1 · immutable
·published 2007-11-14 13:05 UTC
rendered paste body
void put(unsigned c){
	putchar('#' + (c < '\\' ? c : c+1));
}
int get(char c){
	return (c < '\\' ? c : c-1) - '#';
}

void encode(char *name, unsigned *a, int n){
	printf("char %s[]=\"", name);
	for(int i=0; i<n; ++i){
		unsigned t = a[i];
		t <<= 2;
		for(int j=0; j<5; ++j){
			put((t>>26) & ((1<<6)-1));
			t <<= 6;
		}
	}
	printf("\";\n");
}

void decode(unsigned *a, char *src, int n){
	for(int i=0; i<n; ++i){
		unsigned t = 0;
		for(int j=0; j<5; ++j){
			t <<= 6;
			t |= get(src[i*5+j]);
		}
		a[i] = t;
	}
}