Skip to content

Instantly share code, notes, and snippets.

@GZShi
Created September 29, 2012 06:01
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 GZShi/3803322 to your computer and use it in GitHub Desktop.
Save GZShi/3803322 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#define c1(c) ((((c) << 1) & 0x2a) | (((c) >> 1) & 0x15)) // 交换
#define c2(c) ((c) >> 6) // 循环左移位数
#define c3(c) ((c1((c)) >> 6 - c2((c))) | ((c1((c)) << c2((c))) & 0x3f) | ((c) & 0xc0)) //循环
void encode(char *s);
int main(void)
{
char instr[200];
puts("input a string:");
gets(instr);
encode(instr);
puts(instr);
return 0;
}
void encode(char *s)
{
int i = 0;
while(s[i] != '\0')
s[i++] = (c3(s[i]));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment