资源简介
VC环境下实现希尔密码的加密、解码和破译

代码片段和文件信息
#include “stdafx.h“
#include “HillCode.h“
CHillCode::CHillCode()
: m_szM(NULL) m_szE(NULL) m_matrixEncryKey() m_matrixDiscryKey() m_nLenM(0) m_nLenE(0)
{
}
CHillCode::~CHillCode()
{
if (NULL != m_szM)
{
delete m_szM;
m_szM = NULL;
}
if(NULL != m_szE)
{
delete m_szE;
m_szE = NULL;
}
}
void CHillCode::SetM(const unsigned char *pM)
{
if (NULL != m_szM)
{
delete m_szM;
m_szM = NULL;
}
m_szM = new unsigned char[m_nLenM];
if (NULL == m_szM)
{
exit(1);
}
memcpy((char *)m_szM (const char *)pM m_nLenM);
}
int CHillCode::SetEncryKey(const long * plMatrix const int LEN)
{
int nLen = LEN;
m_nLenM = (int)sqrt((double)nLen);
m_nLenE = m_nLenM;
if(0 >= m_nLenM)
{
return 0;
}
m_matrixEncryKey.InitMatrix(m_nLenM m_nLenM);
int i = 0;
int j = 0;
for(i=0; i {
for(j=0; j {
m_matrixEncryKey.SetElement(i j (long)plMatrix[i*m_nLenM+j]);
}
}
m_matrixDiscryKey = m_matrixEncryKey;
long lPhalanxValue = 0;
lPhalanxValue = m_matrixDiscryKey.GetPhalanxValue();
if(!lPhalanxValue || !(lPhalanxValue%2))
{
return 0;
}
m_matrixDiscryKey.Adjoint();
m_matrixDiscryKey = m_matrixDiscryKey * Reciprocal(lPhalanxValue);
m_matrixDiscryKey.Mod(MAPLEN);
return 1;
}
const char * CHillCode::Encrypting()
{
if(0 == m_szM)
{
return NULL;
}
CMatrix matrixM;
matrixM.InitMatrix(m_nLenM 1);
int i = 0;
for(i=0; i {
matrixM.SetElement(i 0 (long)m_szM[i]);
}
CMatrix matrixE;
long lValue = 0;
if(0 != m_szE)
{
delete m_szE;
m_szE = NULL;
}
matrixE.InitMatrix(m_nLenE 1);
matrixE = m_matrixEncryKey * matrixM;
matrixE.Mod(MAPLEN);
m_szE = new unsigned char[m_nLenE];
if(0 == m_szE)
{
exit(1);
}
for(i=0; i {
matrixE.GetElement(i 0 lValue);
m_szE[i] = (unsigned char)lValue;
}
return (const char *)m_szE;
}
void CHillCode::SetDiscryKey(const CMatrix &matrixDiscryKey)
{
if(matrixDiscryKey.GetRows() != matrixDiscryKey.GetCols())
{
return;
}
m_matrixDiscryKey = matrixDiscryKey;
m_nLenM = matrixDiscryKey.GetCols();
m_nLenE = matrixDiscryKey.GetCols();
}
void CHillCode::SetE(const unsigned char *pE)
{
if (NULL != m_szE)
{
delete m_szE;
m_szE = NULL;
}
m_szE = new unsigned char[m_nLenE];
if (NULL == m_szE)
{
exit(1);
}
memcpy((char *)m_szE (const char *)pE m_nLenE);
}
const char * CHillCode::Discrypting()
{
if(0 == m_szE)
{
return NULL;
}
CMatrix matrixE;
matrixE.InitMatrix(m_nLenE 1);
int i = 0;
for(i=0; i {
matrixE.SetElement(i 0 (long)m_szE[i]);
}
CMatrix matrixM;
long lValue = 0;
if(0 != m_szM)
{
delete m_szM;
m_szM = NULL;
}
matrixM.InitMatrix(m_nLenM 1);
matrixM = m_matrixDiscryKey * matrixE;
matrixM.Mod(MAPLEN);
m_szM = new unsigned char[m_nLenM];
if(0 == m_szM)
{
exit(1);
}
for
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 18329 2009-12-28 10:54 HillCodor\Debug\HillCode.obj
文件 0 2009-12-28 10:54 HillCodor\Debug\HillCode.sbr
文件 3466240 2009-12-28 10:54 HillCodor\Debug\HillCodor.bsc
文件 131153 2009-12-28 10:54 HillCodor\Debug\HillCodor.exe
文件 237892 2009-12-28 10:54 HillCodor\Debug\HillCodor.ilk
文件 16848 2009-12-28 10:54 HillCodor\Debug\HillCodor.obj
文件 9492740 2009-12-28 10:54 HillCodor\Debug\HillCodor.pch
文件 320512 2009-12-28 10:54 HillCodor\Debug\HillCodor.pdb
文件 3860 2009-12-28 10:54 HillCodor\Debug\HillCodor.res
文件 0 2009-12-28 10:54 HillCodor\Debug\HillCodor.sbr
文件 72993 2009-12-28 10:54 HillCodor\Debug\HillCodorDlg.obj
文件 0 2009-12-28 10:54 HillCodor\Debug\HillCodorDlg.sbr
文件 24730 2009-12-28 10:54 HillCodor\Debug\Matrix.obj
文件 0 2009-12-28 10:54 HillCodor\Debug\Matrix.sbr
文件 111628 2009-12-28 10:54 HillCodor\Debug\StdAfx.obj
文件 1607628 2009-12-28 10:54 HillCodor\Debug\StdAfx.sbr
文件 263168 2009-12-28 10:54 HillCodor\Debug\vc60.idb
文件 454656 2009-12-28 10:54 HillCodor\Debug\vc60.pdb
目录 0 2009-12-28 10:54 HillCodor\Debug
文件 296 2005-09-11 22:22 HillCodor\Discryption.txt
文件 296 2005-09-11 22:22 HillCodor\Encryption.txt
文件 3845 2005-09-11 16:07 HillCodor\HillCode.cpp
文件 873 2005-09-11 14:07 HillCodor\HillCode.h
文件 23536 2005-09-11 22:49 HillCodor\HillCodor.aps
文件 2855 2005-09-11 22:51 HillCodor\HillCodor.clw
文件 2105 2005-09-10 14:07 HillCodor\HillCodor.cpp
文件 4466 2005-09-11 22:51 HillCodor\HillCodor.dsp
文件 543 2005-09-10 14:07 HillCodor\HillCodor.dsw
文件 1357 2005-09-10 14:07 HillCodor\HillCodor.h
文件 55808 2005-09-11 22:51 HillCodor\HillCodor.opt
............此处省略22个文件信息
相关资源
- ChilledWindows.exe(玩笑病毒)
- Hillstone SA-2003高性能纯硬件安全网关产
- Hillstone SR-550高性能安全路由器产品手
- Hillstone SR-560高性能安全路由器产品手
- Hillstone SR-320高性能安全路由器产品手
- Hillstone ARP防护——StoneOS如何保
- Hillstone防火墙技术——StoneOS安
- Hillstone SA安全网关解决方案助力校园
- Hillstone SA系列高性能安全网关为中金
- GreenHills 2017.7 编译手册
- GreenHills使用说明
- windchill 中文客制化
- CMOS Analog Circuit Design_3nd_Phillip E. Alle
- windchill安装手册
- 软件工程(英文版-McGraw-Hill
- Windchill常用开发大全
- WINDCHILL项目管理模块使用教程
- windchill专业化管理员指南
- 电路基础第六版McGraw Hill出版,pdf文本
- 数据通信与网络第五版英文版Forouza
- Windchill 10.0 API chm文档
- feedback control system(反馈控制系统第五
- McGraw Hill - Digital Communications By John P
- Introduction to Operations Research (10th Ed
- McGrawHill-MachineLearning-TomMitchell.zip
- hillstone 固件
- hillstone secure connect Mac版
- hillstone secure connect Mac版
- 移动通信(第二版,Jochen Schiller)习
- Hill准则渐进损伤准则-显示算法
评论
共有 条评论