//PLAYFAIR
H 头文件 #ifndef _PLAY_FAIR_H_ #define _PLAY_FAIR_H_ void cst_playfair_table (char *in_key); void prnt_playfair_table (); int playfair_encrypt (char *plain_txt, char *cipher_txt); int playfair_decrypt (char *cipher_txt, char *plain_txt); #endif //PLAYFAIR
C 源文件 #include "playfair
h" #include #include #include char playfair_table[5][5]; void get_x_y (char c, int *x, int *y) { int i, j; for (i = 0; i < 5; ++i) { for (j = 0; j < 5; ++j) { if (playfair_table[i][j] == c) { *x = i; *y = j; return; } } } } char get_char_x_y (int x, int y) { if (x < 0) x += 5; if (y < 0) y += 5; return playfair_table[x % 5][y % 5]; } void cst_playfair_table (char *in_key) { int i = 0, j, k; int char_count = 0, left_ch_index = 0; char ch, left_chs[26] = {0}, key[26] = {0}; int key_len; strcpy (key, in_key);