- 博客(51)
- 资源 (2)
- 收藏
- 关注
原创 缓冲区溢出_调用DOS窗口
#include #include char name[] = "\x41\x41\x41\x41" //name[0]-name[3] "\x41\x41\x41\x41" //name[4]-name[7] "\x41\x41\x41\x41" "\x12\x45\xfa\x7f" "\x55\x8B\xEC\x33\xC0" "\x50\x50\x5
2012-04-14 13:01:48
464
原创 素性测试
#include #include #include #include using namespace std; class judge_prime { public: int Btest(int a,int n); int MillRab(int n); int RepeatMillRab(int n,int k); }; int jud
2012-03-09 19:51:02
654
转载 RC4
/*++ Copyright (c) 2009-2010 Sagittarius->Chinese watermelon Module Name: rc4.h Abstract: 加密算法RC4 *RC4 functions for HTMLDOC. * * Original code by Rob Earhart * Copyrig
2012-03-06 21:34:01
1191
转载 AES加密
aes.h /********************************************************************************************* AES的C语言实现 这段代码系参考>和一些密码学资料写的,算是我的一个原创作品。 此代码仅仅作为研究AES算法之用。在效率方面没有优化,但是代码的正确性可以保证。
2012-03-04 13:36:23
456
原创 AES加密中列混合的具体算法
AES明文在加密过程中涉及到字节代换、行移位、列混合、轮密钥加等过程。这里对列混合的算法做出一些浅显的解释。 列混合其实就是对一个状态的每一列去乘一个矩阵,其中乘法是在有限域GF(2^8)内进行的,不可约多项式为x^8+x^4+x^2+x+1如图: 先把算法代码列出来: void AES::MixColumns(unsigned char state[][4]) //列混合
2012-03-02 19:27:17
1439
转载 DES
DES的可逆性证明: 记 DES第 i轮中的主要运算为,即 Fi(Li –1,Ri -1)=(Li -1⊕f(Ri -1, Ki),R i -1) 则Fi^ 2=Fi(Li -1⊕f(Ri -1, Ki),R i -1) =(Li -1⊕f(Ri -1, Ki)⊕f(Ri -1, Ki),R i -1) =(Li –1
2012-02-25 13:53:04
903
原创 Eratosthenes筛法求10000以内的质数
#include using namespace std; int main() { int prime[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43, 47,53,59,61,67,71,73,79,83,89,97}; //100以内的质数 int seq[10000]; for(int i=0; i<10000;
2012-02-20 14:18:53
1047
转载 typedef 函数指针的用法
typedef 函数指针的用法 在网上搜索函数指针,看到一个例子。开始没看懂,想放弃,可是转念一想,这个用法迟早要弄懂的,现在多花点时间看懂它,好过以后碰到了要再花一倍时间来弄懂它。其实很多时候都是这样,如果每次到难一点的内容,总想着下次我再来解决它,那就永远也学不到东西。 后面那个例子加了注释,是我对这种用法的理解,希望对新手有所帮助。 进入正文: 代码简化, 促进跨平台
2012-02-15 11:49:35
184
原创 实现随机密钥加密文章的仿射密码
#include #include #include #include using namespace std; int keyA[12]={1,3,5,7,9,11,15,17,19,21,23,25}; //具有mod26乘法逆的12个元素 int keyB[26]; char encode(char ch, int key_a, int key_b) //加密
2012-02-12 20:36:38
398
转载 C++中的随机函数
一、random函数不是ANSI C标准,不能在gcc,vc等编译器下编译通过。 可改用C++下的rand函数来实现。 1、C++标准函数库提供一随机数生成器rand,返回0-RAND_MAX之间均匀分布的伪随机整数。 RAND_MAX必须至少为32767。rand()函数不接受参数,默认以1为种子(即起始值)。 随机数生成器总是以相同的种子开始,所以形成的伪随机数列也相同,失去了随机
2012-02-12 19:21:37
487
原创 统计文章中英文字母的频度
#include #include #include #include #include using namespace std; int main() { mapd; ifstream ifs("d:\\data.txt"); char c; while(ifs>>c) { if(isalpha(c)) { char word=tolo
2012-02-09 19:50:43
568
原创 仿射密码的C++实现
//加密:e(x)=(ax+b)modm; //解密:d(y)=a-1(y-b)modm; #include using namespace std; int a,b,c; void encode(char* seq, char* out) //加密函数 { int temp; char res; for(int i=0; seq[i]; ++i) {
2012-02-08 20:35:05
1233
原创 4.3 numeric limits
#include #include #include using namespace std; int main() { cout<<boolalpha; cout::max()<<endl; cout::max()<<endl; cout::max()<<endl; cout<<endl; cout::max()<<endl; cout::
2011-12-30 20:44:46
232
原创 auto_ptr
#include namespace std { template struct auto_ptr_ref { Y* yp; auto_ptr_ref(Y* rhs): yp(rhs) {} }; template class auto_ptr { private: T* ap; public: typedef T elem
2011-12-29 20:57:46
441
转载 反转字符串
题目要求:把字符串“I am a student”反转成为“student a am I”,不借助任何库函数。 字符串中单词顺序反转的方法有很多种,我们可以定义一个栈结构,根据栈的特性,先进后出。我们通过依次查找空格(在实际分析单词应用中这只是最简单的情况,单词之间可能直接用标点符号区分,但是使用标点符号并不意味着就是两个单词,西方世界计数方式喜欢使用三位数
2011-12-05 20:57:38
1284
原创 作业题3.38,关于缓冲区溢出
原题为: 输入一个16进制的字符串, 使得程序输出0xdeadbeef 程序如下: /* Bomb program that is solved using a buffer overflow attack */ #include #include #include /* Like gets, except that characters are ty
2011-11-09 15:38:03
639
原创 test
1、gcc -c main.c 2、gcc -o prog main.o 3、objdump -d prog.exe>prog_obj.s 4、gdb prog 5、 6、
2011-11-08 21:33:00
110
原创 test
/* Bomb program that is solved using a buffer overflow attack */ #include "stdio.h" #include "stdlib.h" #include "ctype.h" #include "malloc.h" /* Like gets, except that characters are typed a
2011-11-06 21:58:45
91
转载 C程序栈原理及例子浅析
首先看如下图-1演示的用c语言编写的例子程序。 ┌————————————————————┐ │ 1. void fun() │ │ 2. { │ │ 3. printf(“Hello World\n”); │ │ 4.
2011-10-30 16:46:04
1367
原创 c语言中浮点数的表示
IEEE 754标准中,浮点数的表示方法如下: V=(-1)s×M×2E 其中: 1、s是符号位,占1个字符。s为1表示负数,s为0表示正数; 2、M是二进制小数,32位单精度float中M占23位,形式如同fn-1fn-2。。。f1f0(n=23); 3、E是指数位,32位单精度float中E占8位,形式如同ek-1。。。e1e0(k=8); 总体上,浮点数编码分作三类: 1
2011-10-20 17:07:57
3957
原创 19 Froyd-Warshall算法
Froyd-Warshall算法用于求解所有点对之间的最短距离,其中权值可以为负值,但是不能有负数的环。时间复杂度为O(n^3)。 该算法的思路是, 第一步:所有从 i 到 j 的最短路径为i、j之间的权值(不相连的话就设为某个MAX数值)
2011-10-19 14:43:37
433
原创 18 Bellman-Ford算法
#include using namespace std; const int maxnum = 100; const int maxint = 99999; // 边 typedef struct Edge{ int u, v; // 起点,终点
2011-10-15 09:48:05
268
原创 17 单源最短路径,以及补全16讲MST的一些代码
16、17讲开始涉及到图,光是伪代码的话实现起来不是很直接,所以干脆补全一下需要用到的图的类定义及一些成员函数,限于篇幅,成员函数、最小堆、并查集等的实现没有贴出来。 graph类定义 template class Graph { public: Graph
2011-10-08 17:04:08
1186
原创 Lecture 16 最小生成树 Prim算法
Prim算法 例如下面的无向连通图: #include #include #include using namespace std; struct TreeNode // 边结点定义 { public: TreeNode (int
2011-10-07 11:14:36
2946
原创 15 思考题 编辑距离
/* 描述: 设A和B是2个字符串。要用最少的字符操作将字符串A转换为字符串B。这里所说的字符操作包括: (1)删除一个字符; (2)插入一个字符; (3)将一个字符改为另一个字符。 将字符串A变换为字符串B所用的最少字符操作数称为字符串A到B的编辑距离,记为d(A,
2011-10-01 18:03:44
1363
原创 15 动态规划-装配线调度
#include using namespace std; int n; // 一个装配线上有n个装配站 int e1, e2; // 进入装配线1,2需要的时间 int x1, x2;
2011-09-30 21:15:34
255
原创 15 动态规划-最长上升子序列
问题描述:给出一个序列a1,a2,a3,a4,a5,a6,a7….an,求它的一个子序列(设为s1,s2,…sn),使得这个子序列满足这样的性质,s1 例如有一个序列:1 7 3 5 9 4 8,它的最长上升子序列就是 1 3 4 8 长度为4 算法一(时间
2011-09-29 20:11:15
447
原创 15.4 最长公共子序列
#include using namespace std; char x[30], y[30]; int c[30][30]; char b[30][30]; void LCS() { int m=strlen(x+1); int n=strlen(
2011-09-29 13:18:48
372
原创 Lecture 12 跳表
#include #include #include using namespace std; const int DefaultSize=100; template struct SkipNode { E data; SkipNode * *
2011-09-25 14:23:29
285
原创 13 红黑树
#include using namespace std; typedef enum col{RED, BLACK} col; template class RBNode { public: RBNode(T k, RBNode* l=NULL, RB
2011-09-18 13:58:27
220
原创 12 二叉查找树
#include using namespace std; typedef struct Node //树结点定义 { int key; Node *lchild, *rchild, *parent; }Node, *BSTree; Nod
2011-09-14 16:06:47
226
原创 11.4 双重散列法
#include #include #include #include #include #define slot_size 100000 //散列槽的大小 #define arr_size 80000 //动态关键字集合 #define min_s
2011-09-04 12:40:20
2492
原创 11.3 除法散列法
#include #include #include #include #include #define slot_size 20000 //散列槽的大小 #define arr_size 100000 //动态关键字集合 #define min_si
2011-09-03 10:09:11
556
原创 9.3 最坏情况下线性时间选择
#include #include #include #define MAX_VALUE 10000 #define random() rand()%MAX_VALUE #define N 10000 using namespace std; int a
2011-09-01 13:39:27
366
原创 9.3 最坏情况下的线性时间选择算法
#include #include #include using namespace std; void init(vector& v, int n) //初始化,产生n个随机数 { srand((unsigned)tim
2011-08-30 16:41:22
228
原创 9.2 第i个顺序统计量
运行时间为θ(n) #include #include #include #include using namespace std; void input(vector& v) {
2011-08-29 13:42:42
301
原创 8.4 桶排序
数据在(0,1)之间 #include #include #include using namespace std; /*initial arr*/ void InitialArr(double *arr,int n) { srand((unsign
2011-08-26 13:55:04
198
原创 8.3 基数排序
#include #include #include using namespace std; const int NUM=3; //位数 void input(vector& v) {
2011-08-25 20:00:38
160
原创 8.2 计数排序
#include #include #include using namespace std; void input(vector& v) { int data; while(cin>>data)
2011-08-24 20:20:23
180
原创 7.3 快速排序的随机化版本
运行时间为nlgn #include #include #include #include using namespace std; void input_v(vector &v) { int data; while(cin>>
2011-08-23 21:14:16
250
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人