//PLAYFAIR.H 头文件
#ifndef _PLAY_FAIR_H_
#dene _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 <stdio.h>
#include <stdlib.h>
#include <string.h>
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];
}