博文

Short introduction to BASE64

BASE64算法是一个常见的加密算法,可以实现对文本的加密,据说还可以将二进制的文件转换成文本文件,通常电脑中的所有的文件都是以二进制流的形式存 储在硬盘上的,这样一来,也许所有的文件都可以转换为文本了吧:)!不管怎么说,其转换的算法都是想同的,下面以简单的ASCII文本为例,介绍一下 BASE64算法的转换过程!     我们知道通常的计算机系统当中,一个字节是由8个二进制位组成的,例如“A”的ASCII编码值是十进制数的65,转换成二进制数就是 “01000001”,而BASE64算法就是在这样的二进制的基础上进行编码的。算法首先取3个字节的数据,转换成二进制,我们就用可爱的企鹅举个例子 吧:         “TUX” 转换成二进制:         “01010100 01010101 01011000” 注意:这里每个字节间的空格实际上是不存在的 这样我们就得到了8*3=24个二进制位组成的序列,然后再将这24个位每6个分一组,分成24/6=4组:         “010101 000101 010101 011000” 将这四个分组高位补零,形成可以转换为一个字节的8位:         “00010101 00000101 00010101 00011000” 再将这四个字节转换成十进制数:         “21 5 21 24” 接下来我们要构建一个编码表:         0    A     17 R     34 i     51 z ...

Master theorem 主定理及其应用算法

图片
Generic form The master theorem concerns recurrence relations of the form: In the application to the analysis of a recursive algorithm, the constants and function take on the following significance: n  is the size of the problem. a  is the number of subproblems in the recursion. n / b  is the size of each subproblem. (Here it is assumed that all subproblems are essentially the same size.) f  ( n ) is the cost of the work done outside the recursive calls, which includes the cost of dividing the problem and the cost of merging the solutions to the subproblems. Application to common algorithms Algorithm Recurrence Relationship Run time Comment Binary search O (log( n )) Apply Master theorem where  f ( n ) =  n c [3] Binary tree traversal O ( n ) Apply Master theorem where  f ( n ) =  n c [3] Optimal Sorted Matrix Search O ( n ) Apply  Akra-Bazzi theorem  for  p  = 1  and  g ( u ) = log( u ) ...

Linux 缓冲区溢出

1.什么是缓冲区溢出? ~~~~~~~~~~~~~~~~~~~ buffer overflow,buffer overrun,smash the stack,trash the stack, scribble the stack, mangle the stack,spam,alias bug,fandango on core, memory leak,precedence lossage,overrun screw...指的是一种系统攻击的手 段,通过往程序的缓冲区写超出其长度的内容,造成缓冲区的溢出,从而破坏程 序的堆栈,使程序转而执行其它指令,以达到攻击的目的。据统计,通过缓冲区 溢出进行的攻击占所有系统攻击总数的80%以上。 造成缓冲区溢出的原因是程序中没有仔细检查用户输入的参数。例如下面程 序: example1.c ---------------------------------------------------------------------- void function(char *str) { char buffer[16]; strcpy(buffer,str); } ---------------------------------------------------------------------- 上面的strcpy()将直接吧str中的内容copy到buffer中。这样只要str的长度 大于16,就会造成buffer的溢出,使程序运行出错。存在象strcpy这样的问题的 标准函数还有strcat(),sprintf(),vsprintf(),gets(),scanf(),以及在循环内的 getc(),fgetc(),getchar()等。 当然,随便往缓冲区中填东西造成它溢出一般只会出现Segmentation fault 错误,而不能达到攻击的目的。最常见的手段是通过制造缓冲区溢出使程序运行 一个用户shell,再通过shell执行其它命令。如果该程序属于root且有suid权限 的话,攻击者就获得了一个有root权限的shell,可以对系统进行任意操作了。 请注意,如果没有特别说明,下面的内容都假设用户使用的平台为基于Intel x86 CPU的Linux系统。对其...

Python 正则表达式反斜杠的麻烦

在早期规定中,正则表达式用反斜杠字符 ("\") 来表示特殊格式或允许使用特殊字符而不调用它的特殊用法。这就与 Python 在字符串中的那些起相同作用的相同字符产生了冲突。 让我们举例说明,你想写一个 RE 以匹配字符串 "\section",可能是在一个 LATEX 文件查找。为了要在程序代码中判断,首先要写出想要匹配的字符串。接下来你需要在所有反斜杠和其它元字符前加反斜杠来取消其特殊意义,结果要匹配的字符串 就成了"\\section"。 当把这个字符串传递给re.compile()时必须还是"\\section"。然而,作为Python的字符串实值(string literals)来表示的话,"\\section"中两个反斜杠还要再次取消特殊意义,最后结果就变成了"\\\\section"。 字符 阶段 \section 要匹配的字符串 \\section 为 re.compile 取消反斜杠的特殊意义 "\\\\section" 为"\\section"的字符串实值(string literals)取消反斜杠的特殊意义 简单地说,为了匹配一个反斜杠,不得不在 RE 字符串中写 '\\\\',因为正则表达式中必须是 "\\",而每个反斜杠在常规的 Python 字符串实值中必须表示成 "\\"。在 REs 中反斜杠的这个重复特性会导致大量重复的反斜杠,而且所生成的字符串也很难懂。 解决的办法就是为正则表达式使用 Python 的 raw 字符串表示;在字符串前加个 "r" 反斜杠就不会被任何特殊方式处理,所以 r"\n" 就是包含"\" 和 "n" 的两个字符,而 "\n" 则是一个字符,表示一个换行。正则表达式通常在 Python 代码中都是用这种 raw 字符串表示。 常规字符串 Raw 字符串 "ab*" r"ab*" "\\\\section...

Accessing Jython from Java Without Using jythonc

You may or may not know that it is possible to access Jython code from Java without compiling it using the jythonc utility. This technique is possible using a mixture of Java interfaces and usage of the  PythonInterpreter . As a matter of fact, I believe that using this technique correctly is more effective than using jythonc. To put it simply, to use this technique you must create a "factory" method which uses the  PythonInterpreter  class to interpret a .py module for use within Java code. Any Java code that uses the Jython code should be coded against an interface which is implemented by the Jython code. In order to provide a fully functional example, I've created a simple application with hard-coded data. This application shows the potential for using this technique within your Java applications to have the ability for use of dynamic Jython objects. The application is simply called "jyinterface" and it contains four pieces of code: -Main.java - Jyt...

How to Build an HTML5 Video Player

http://blog.steveheffernan.com/2010/04/how-to-build-an-html5-video-player/

Stateful Session Bean Example

In this part of Enterprise Session Beans, you will learn how to develop, deploy, and run a simple Java EE application named account using stateful session bean. The purpose of account is to performs two transaction operations (deposit and withdraw) for the customer. The account application consists of an enterprise bean, which performs the transactions, and two types of clients: an application client and a web client . here are following steps that you have to follow to develop a account JEE application . Create the enterprise bean: AccountBean Create the application client: AccountCustomer Deploy account onto the server. Run the application client. I. Creating the enterprise bean: The enterprise bean in our example is a statelful session bean called AccountBean. The account session bean represents an account information in an online customer account. The bean’s customer can deposit to or withdraw the amount from his account. To manage account, you...