servlet

04月 18th, 2012

servlet-basic-07

struts2环境搭建和第一个struts2应用

04月 18th, 2012

struts2下载地址
http://apache.etoak.com/struts/binaries/

找到开发struts2应用需要使用到的jar文件
编写struts2的配置文件struts.xml
在web.xml中加入Struts2 MVC框架启动配置

具体操作步骤:

  1. 创建web项目
  2. 导入Jar文件
  3. 编写struts2配置文件,struts.xml开发阶段放在src目录下面,配置文件的模板可以从struts2包的例子里面烤,也可以从文档里面烤。例子在apps目录下面,解压下面的包,\apps\struts2-blank\WEB-INF\classes目录下面就有struts.xml文件了。
  4. 在WEB-INF文件夹下面新建web.xml,加入代码。

第一个struts2应用:

  • 新建Action类和编写execute方法
  • 新建jsp文件,定义视图

字符串比较实例

02月 22nd, 2012
?Download dowload.c
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define ANSWER "GRANT"
#define MAX 40
void tup(char *, int );
int main(int argc, char * argv[])
{
  char try[MAX];
  puts("Who is buried in Grant's tomb?");
  gets(try);
  tup(try, strlen(try));
  while (strcmp(ANSWER, try)) { 
    puts("No, thats wrong, Try again."); 
    gets(try);
    tup(try, strlen(try));
  } 
  puts("Thats right."); 
  return 0;
}
//将字符串中的小写字母转换成大写字母
void tup(char *s, int n)
{
 
  int i;
  for (i = 0; i < n; i++)
    {
      if (*(s + i) >= 'a' && *(s + i) <= 'z')
	*(s + i) -= 32;
    }
}

test

02月 21st, 2012

test

post blog

01月 27th, 2012

好久没有POST了。

今天随便发发吧!

統計輸入C語言关键字

05月 12th, 2011
#include 
#include 
#include 
//#define NKEYS (sizeof (keytab) / sizeof(struct key))
#define MAXWORD 100
struct key {
  char *word;
  int count;
} keytab[] = {
  {"auto", 0},
  {"break", 0},
  {"case", 0},
  {"char", 0},
  {"const", 0},
  {"continue", 0},
  {"default", 0},
  {"do", 0},
  {"double", 0},
  {"else", 0},
  {"enum", 0},
  {"extern", 0},
  {"float", 0},
  {"for", 0},
  {"goto", 0},
  {"if", 0},
  {"int", 0},
  {"long", 0},
  {"register", 0},
  {"return", 0},
  {"short", 0},
  {"signed", 0},
  {"sizeof", 0},
  {"static", 0},
  {"struct", 0},
  {"struct", 0},
  {"switch", 0},
  {"typedef", 0},
  {"union", 0},
  {"unsigned", 0},
  {"void", 0},
  {"volatile", 0},
  {"while", 0},
};

//#define NKEYS (sizeof (keytab) / sizeof(struct key))
#define NKEYS (sizeof keytab / sizeof keytab[0])
int binsearch(char *word, struct key tab[], int n);
int getword(char *word, int lim);

main()
{
  int n;
  char word[MAXWORD];

  /* 統計輸入 */
  while (getword(word, MAXWORD) != EOF)
    if (isalpha(word[0]))
      if ((n = binsearch(word, keytab, NKEYS)) >= 0)
	keytab[n].count++;
  for (n = 0; n < NKEYS; n++)
    if (keytab[n].count > 0)
      printf("%4d %s\n",
	     keytab[n].count, keytab[n].word);
  return 0;
}

int binsearch(char *word, struct key tab[], int n)
{
  int cond;
  int low, mid, high;

  low = 0;
  high = n - 1;
  while (low <= high) {
    mid = (high + low) / 2;
    if ((cond = strcmp(word, tab[mid].word)) < 0)
      high = mid - 1;
    else if (cond > 0)
      low = mid + 1;
    else
      return mid;
  }
  return -1;
}

#define BUFSIZE 100
char buf[BUFSIZE];
int bufp = 0;

int getch(void)
{
  return (buf < 0) ? buf[--bufp] : getchar();
}

void ungetch(int c)
{
  if (bufp >= BUFSIZE)
    printf("ungetch: too many characters\n");
  else
    buf[bufp++] = c;
}
int getword(char *word, int lim)
{
  int c, getch(void);
  void ungetch(int);
  char *w = word;

  while (isspace(c = getch()))
    ;
  if (c != EOF)
    *w++ = c;
  if (!isalpha(c)) {
    *w = '\0';
    return c;
  }
  for ( ; --lim > 0; w++)
    if (!isalnum(*w = getch())) {
      ungetch(*w);
      break;
    }
  *w = '\0';
  return word[0];
}

ipass 讀取密碼

04月 28th, 2011

聯通IPASS讀取密碼的方法:

前提:在讀取密碼前需要將IPASS插入電腦,並且撥號,成功連接互聯網。

使用軟體:WinHex

步驟一:

ipass1

打開后在里面查找IPASS的進程。

步驟二:搜索,一般帳號前幾位數字是e2009,一般一搜索就會出現。

這就是帳號拉

未命名

密碼就在附近了,上面或下麵,仔細查找就會發現哦。

這就是密碼拉:

1111

注:這個方法是我的錢同學告訴我的,非常感謝錢同學。

变长参数表(转)

04月 24th, 2011

有些函数的形参表中有”…”,它代表变长参数表,即”…”可用若干个实参取代。适用于有“维数不定的数组”的函数。如果是二维数组
参数中要包括两维的长度,有两个整型量;如果是三维数组,参数中包括三维的长度,有三个整型量。随着维数不同,参数的个数也同,
这就必须使用变长参数表个数不定的问题。变长参数表的操作在C的库函数中有一套完整的实现数据类型和函数,包含在头文件stdarg.h中
变长参数表类型标识符va_list,函数有:va_start(),va_arg(),va_end()
1. va_start(va_list ap,elemtype ***),此函数的形参表中ap为变长参数表类型,***为引用该变长参数的函数形参表中变长参前
边的参变量;该函数的功能:将ap指向变长参数表。
2.va_arg(ap,elemtype)此函数为一个有返回值的某一类型的函数,其返回类型为变长参数表中参数的类型,此函数的形参表中ap变
长参数表类型,elemtype为变长参数表中参数的类型;函数的功能:返回ap指向变长形参表中的实参量。(ap在函数内部充当指针的作用,含有ap++的功能,在循环中可以移动)。
3.va_end(ap)此函数与va_start(va_list ap,int num)配对使用,函数的功能:结束对变长参数表的读取,ap不再指向变长参数表,和//free()功能相似。

#include <stdio.h>
#include <stdarg.h>
#include <process.h>
typedef int ElemType;
ElemType Max(int num,...)
{
va_list ap;
     int i;
     ElemType m,n;
     if(num<1)
           exit(0);
     va_start(ap,num);
     m=va_arg(ap,ElemType);
     for(i=1;i<num;++i)
           {
                 n=va_arg(ap,ElemType);
                 if(m<n)
                       m=n;
           }
     va_end(ap);
     return m;
}
main()
{
     printf("1.输出7,9,5,8中的最大数:\n%4d\n",Max(4,7,9,5,8));
     printf("2.输出17,36,15,28,47,39中的最大数:\n%4d\n",Max(6,17,36,15,28,47,39));
}

“C语言的从右到左入栈的特性使其可以实现如printf之类的变长参数函数”
这是个命题,而且是个真命题。晚上查阅了一些资料,先总结如下:
(1)变长参数列表和固定参数的区别:
我们写的大部分函数都是固定参数函数(至少我没有写过变长参数函数),编译之后,形参的地址是固定的,而且被调用函数也知道形参的地址,所以可以正确取值。比如int func(int a,int b)。
(2)printf() 变长参数如何取值的?
printf函数原型中,第一个参数是不变的,一定是一个格式字符串,后面参数的个数和内容取决于第一个参数的内容,所以又称为变长参数。在printf的实现中,不难看出,被调用函数只有在取到第一个参数后,才能确定后面参数类型和个数,所以编译器务必要把第一参数房子一个固定的位置,这个位置就是%ebp+8。

RSA算法的原理

04月 20th, 2011

RSA(Rivest-Shamir-Adleman)算法是基于大数不可能被质因数分解假设的公钥体系。简单地说就是找两个很大的质数。一个用来做对外公开的公钥(Public key),另一个不告诉任何人,称为私钥(Private key)。
RSA体制的密钥生成可以简单描述如下:
(1)选择两个大素数p和q(p≠q)。(一般为100位以上的十进制数)
(2)计算出n=p*q及φ(n)=(p-1)(q-1) ,这里φ(n)是Euler函数。
(3)选择一个随机整数e(加密密钥),且满足1<e<φ(n),满足gcd(e,φ(n))=1。
(4)计算解密密钥  e*d  mod φ(n)=1,计算解密密钥d.
(5)明文为a ,对每一个密钥k=(n,p,q,d,e),定义加密变换为:Ek(a)= aemod n = c,定义解密变换为:Dk(c)= cd mod n = a。
(6)公布整数n和加密密钥e。以{e,n}作为公开密钥,以{d,n}作为私有密钥。

例题一:

P=7,q=19,选择e=5,求d=?

明文为6,求密文。

解:
n=p*q=7*19=133, φ(n)=6*18=108
e=5,  e与108互质,满足要求
5d mod 108=1
某个数 5d  除以108,余数为1

求5的倍数:

  1. 108*1+1=109
  2. 108*2+1=217
  3. 108*3+1=325
  4. 5d=325
  5. d=65

加密: c=6^5 mod 133=62
验证: 62^65 mod 133=6

例题二:

两个质数p=11,q=13,请选择一个e,然后求d=?明文为85,求密文。

解:
n=p*q=11*13=143,φ(n)=(p-1)*(q-1)=(11-1)*(13-1)=120
选e=7,e与120互质,满足要求
7d mod 120 = 1
某个数7d除以120,余数为1,求7的倍数:

  1. 120*1+1=121
  2. 120*2+1=241
  3. 120*3+1=361
  4. 120*x+1=xxx
  5. 120*6+1=721

721为7的倍数
7d=721      d=103
加密: c=85^7 mod 143 = 123
验证: 123^103 mod 143 = 85

ubuntu系统启动菜单变多

01月 25th, 2011

原帖地址:http://forum.ubuntu.org.cn/viewtopic.php?f=48&t=315186&p=2196457#p2196457

ubuntu10.04我用了大概有半年多了吧,使用的时间长了,系统启动菜单选项变的越来越多,原来是内核一次一次更新,添加到菜单了,一般都选的最新内核进入系统,所以那么多菜单看着就那么没有必要了。

有朋友推荐使用ubuntu tweak,很不幸我的系统不能用,好像因为Tweak好久没有更新了。下面又朋友说使用:

sudo aptitude purge ~ilinux-image-2.*(! `uname -r`)

下面关于这个命令的一些内容。关于aptitude命令linuxtoy有介绍:

http://linuxtoy.org/archives/aptitude_quick_reference.html

aptitude purge pkgname 删除包及其配置文件。

用于删除内核镜像包吧。 具体我只能看懂这么多了。得再去问问。