?? cdma f8f9 speed testdlg.cpp
字號:
// CDMA f8f9 speed testDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CDMA f8f9 speed test.h"
#include "CDMA f8f9 speed testDlg.h"
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
extern void Kasumi(char*,const char*);
extern int hextoint(char x);
extern char inttohex(int x);
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCDMAf8f9speedtestDlg dialog
CCDMAf8f9speedtestDlg::CCDMAf8f9speedtestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCDMAf8f9speedtestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCDMAf8f9speedtestDlg)
m_f8_data_quantity = _T("");
m_f8_time = _T("");
m_f9_data_quantity = _T("");
m_f9_time = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCDMAf8f9speedtestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCDMAf8f9speedtestDlg)
DDX_Control(pDX, IDC_F9_PROGRESS, m_f9_prog);
DDX_Control(pDX, IDC_F8_PROGRESS, m_f8_prog);
DDX_Text(pDX, IDC_F8_DATA_QUANTITY, m_f8_data_quantity);
DDX_Text(pDX, IDC_F8_TIME, m_f8_time);
DDX_Text(pDX, IDC_F9_DATA_QUANTITY, m_f9_data_quantity);
DDX_Text(pDX, IDC_F9_TIME, m_f9_time);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCDMAf8f9speedtestDlg, CDialog)
//{{AFX_MSG_MAP(CCDMAf8f9speedtestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_EN_CHANGE(IDC_F8_DATA_QUANTITY, OnChangeF8DataQuantity)
ON_EN_CHANGE(IDC_F9_DATA_QUANTITY, OnChangeF9DataQuantity)
ON_BN_CLICKED(IDC_F8_TEST, OnF8Test)
ON_BN_CLICKED(IDC_F9_TEST, OnF9Test)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCDMAf8f9speedtestDlg message handlers
BOOL CCDMAf8f9speedtestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CCDMAf8f9speedtestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CCDMAf8f9speedtestDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CCDMAf8f9speedtestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
// f8數據量
void CCDMAf8f9speedtestDlg::OnChangeF8DataQuantity()
{
UpdateData(TRUE);
m_f8_prog.SetPos(0);
m_f8_time="";
UpdateData(FALSE);
}
// f9數據量
void CCDMAf8f9speedtestDlg::OnChangeF9DataQuantity()
{
UpdateData(TRUE);
m_f9_prog.SetPos(0);
m_f9_time="";
UpdateData(FALSE);
}
// 用f8處理設定的數據量
void CCDMAf8f9speedtestDlg::OnF8Test()
{
UpdateData(TRUE);
m_f8_time = "";
UpdateData(FALSE);
RedrawWindow();
CTime time1, time2;
time1 = time1.GetCurrentTime();
int i,k;
int n=0;
for(i=0;i<m_f8_data_quantity.GetLength();i++)
n += hextoint(m_f8_data_quantity[i]) * (int)pow((double)10,(double)m_f8_data_quantity.GetLength()-1-i);
// 進度條的設置點不能超過65535
if(n>199)
{
MessageBox("請輸入0~199之間的數據!", "參數輸入錯誤", MB_OK | MB_ICONERROR);
return ;
}
n=n*1024*1024/3200;
m_f8_prog.SetPos(0);
m_f8_prog.SetRange(0, n);
m_f8_prog.SetStep(1);
// 用f8處理數據
for (k=0;k<n;k++)
{
//3200bit的數據量為一個標注點
char temp[33];
//常數km,128bit
char m_ck[]="00000000000000000000000000000000";
char km_128bit[]="0123456789ABCDEF0123456789ABCDEF";
//初始化A
char A[]="0000000000000000";
for (i=0;i<32;i++)
temp[i]=inttohex(hextoint(m_ck[i])^hextoint(km_128bit[i]));
temp[32] = '\0';
int length = 3200;
char p[]="0000000000320000";
char q[]="00000000000000000000000000000000";
Kasumi(p,temp);
int blocks;
if (length%64==0)
blocks=length/64;
else blocks=length/64+1;
char *ks;
ks = new char[16*blocks];
for(i=0;i<16;i++)
ks[i]='0';
for(i=0;i<blocks;i++)
{
int j;
for (j=0;j<16;j++)
A[j]=p[j];
A[14]=inttohex(hextoint(A[14])^(i>>4));
A[15]=inttohex(hextoint(A[15])^(i&15));
if(i!=0)
for(j=0;j<16;j++)
A[j]=inttohex( hextoint(A[j]) ^ hextoint(ks[j+(i-1)*16]) );
Kasumi(A,q);
for(j=0;j<16;j++)
ks[j+i*16]=A[j];
}
int num;
if (length%4!=0)
{
num=(int)floor(length/4);
int left_over=length%4;
ks[num]=inttohex( hextoint(ks[num]) >> (4-left_over) );
}
else
num=(int)floor(length/4)-1;
char *ks_display;
ks_display = new char[num+1];
for(i=0;i<num+1;i++)
ks_display[i]=ks[i];
ks_display[i]='\0';
delete []ks;
m_f8_prog.StepIt();
}
time2 = time2.GetCurrentTime();
CTimeSpan times = time2 - time1;
m_f8_time.Format("%02d:%02d:%02d", times.GetHours(), times.GetMinutes(), times.GetSeconds());
UpdateData(FALSE);
}
// 用f9處理設定的數據量
void CCDMAf8f9speedtestDlg::OnF9Test()
{
UpdateData(TRUE);
m_f9_time="";
UpdateData(FALSE);
RedrawWindow();
CTime time1, time2;
time1 = time1.GetCurrentTime();
int i,k;
int n=0;
for(i=0;i<m_f9_data_quantity.GetLength();i++)
n += hextoint(m_f9_data_quantity[i]) * (int)pow((double)10,(double)m_f9_data_quantity.GetLength()-1-i);
if(n>199)
{
MessageBox("請輸入0~199之間的數據!", "參數輸入錯誤", MB_OK | MB_ICONERROR);
return ;
}
n=n*1024*1024/3200;
m_f9_prog.SetPos(0);
m_f9_prog.SetRange(0, n);
m_f9_prog.SetStep(1);
// 用f9處理數據
for (k=0;k<n;k++)
{
char m_hex_f9_indata[832];
for(i=0;i<832;i++)
m_hex_f9_indata[i]='0';
char m_ik[]="00000000000000000000000000000000";
char km_128bit[]="ABCDEF01234567890123456789ABCDEF";
int blocks;
blocks = int(ceil((double)832/16));
char A[]="0000000000000000";
char B[]="0000000000000000";
int j;
for (j=0;j<blocks;j++)
{
for (i=0;i<16;i++)
A[i]=inttohex(hextoint(m_hex_f9_indata[i+j*16])^hextoint(A[i]));
Kasumi(A,m_ik);
for (i=0;i<16;i++)
B[i]=inttohex(hextoint(B[i])^hextoint(A[i]));
}
char temp[32];
for (i=0;i<32;i++)
temp[i]=inttohex(hextoint(m_ik[i])^hextoint(km_128bit[i]));
Kasumi(B,temp);
m_f9_prog.StepIt();
}
time2 = time2.GetCurrentTime();
CTimeSpan times = time2 - time1;
m_f9_time.Format("%02d:%02d:%02d", times.GetHours(), times.GetMinutes(), times.GetSeconds());
UpdateData(FALSE);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -