Одним из методов атак является частотный анализ. Распределение букв в криптотексте сравнивается с распределением букв в алфавите исходного сообщения. Буквы с наибольшей частотой в криптотексте заменяются на букву с наибольшей частотой из алфавита, если он известен. Вероятность успешного вскрытия повышается с увеличением длины криптотекста, поскольку распределения статистические. Существуют множество различных таблиц о распределении букв в том или ином языке, но ни одна из них не содержит окончательной информации - даже порядок букв может отличаться в различных таблицах. Распределение очень сильно зависит от типа теста: проза, разговорный язык, технический язык и т.п. Квадрат Полибия является примером шифра замены, поэтому неустойчив к частотной атаке
Листинг программы.
Эта программа написана на С++
Polibiy.cpp
#include stdafx.h
#include Polibiy.h
#include PolibiyDlg.h
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CPolibiyApp
BEGIN_MESSAGE_MAP(CPolibiyApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
|
|
END_MESSAGE_MAP()
// CPolibiyApp construction
CPolibiyApp::CPolibiyApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
// The one and only CPolibiyApp object
CPolibiyApp theApp;
// CPolibiyApp initialization
BOOL CPolibiyApp::InitInstance()
{
// InitCommonControlsEx() is required on Windows XP if an application
// manifest specifies use of ComCtl32.dll version 6 or later to enable
// visual styles. Otherwise, any window creation will fail.
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// Set this to include all the common control classes you want to use
// in your application.
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
CPolibiyDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the applications message pump.
return FALSE;
}
Paskale
Const
TPolibius: array ['A'.. 'E', 'A'.. 'E'] of char = (
('A', 'B', 'C', 'D', 'E'),
('F', 'G', 'H', 'I', 'K'),
('L', 'M', 'N', 'O', 'P'),
('Q', 'R', 'S', 'T', 'U'),
('V', 'W', 'X', 'Y', 'Z')
);
function PolibiusEncipher(toCode: string): string;
Var
i: integer;
ix, jx: char;
s: string;
Begin
s:= '';
for i:= 1 to length(toCode) do begin
for ix:= 'A' to 'E' do
for jx:= 'A' to 'E' do
if TPolibius[ix, jx] = toCode[ i ] then begin
s:= s + ix + jx; break;
end;
end;
PolibiusEncipher:= s
end;
function PolibiusDecipher(toDecode: string): string;
Var
i: integer;
s: string;
Begin
s:= '';
i:= 1;
while i <= length(toDecode) do begin
s:= s + TPolibius[toDecode[ i ], toDecode[succ(i)]];
inc(i, 2);
end;
PolibiusDecipher:= s
end;
Var
s: string;
Begin
s:= PolibiusEncipher('POLIBIUS');
writeln(s);
writeln('s = ', PolibiusDecipher(s));
end.
Список использованных источников:
Конспект Лекции по Криптографии (Татарникова Т.М.)
Интернет ресурсы.