正在加载...
分页: 173/186 第一页 上页 168 169 170 171 172 173 174 175 176 177 下页 最后页 [ 显示模式: 摘要 | 列表 ]

php中include与require

[ 2008/06/11 18:45 | by selboo ]
require是必须的文件,如果文件找不到,程序将中止。
include则不同,找不到该文件,将直接跳过。下面的继续执行。

至于require_once, include_once,只是为了你同一程序中多次包含了同一文件的时候,只调用一次罢了
require 的使用方法如 require("MyRequireFile.php"); 。这个函数通常放在 PHP 程序的最前面,PHP 程序在执行前,就会先读入 require 所指定引入的文件,使它变成 PHP 程序网页的一部份。常用的函数,亦可以这个方法将它引入网页中。

include 使用方法如 include("MyIncludeFile.php"); 。这个函数一般是放在流程控制的处理部分中。PHP 程序网页在读到 include 的文件时,才将它读进来。这种方式,可以把程序执行时的流程简单化
========================================================
在PHP中include和require到底有什么区别呢?看这里的例子就知道了:
   include.php3的运行结果是:
  这是inc1.inc文件中的一个变量的值!
  这是inc2.inc文件中的一个变量的值!
  inc1.inc文件中的$int变量值为1!

require.php3的运行结果是:
  这是inc1.inc文件中的一个变量的值!
  inc1.inc文件中的$int变量值为2!

你可以看到在require.php3中$int变为了2,也就是说inc1.inc中的语句被执行了2次,这样看来在循环中require语句只被解释一次,而且会把require语句所在的位置用require的文件内容替代并运行,而在循环中include语句每次都会被解释运行。

[sonymusic]补充道:
require是只执行一次的,不,这么说不恰当。应当说,require是先替代,将指定文件的内容代进来,再运行,所以它不知道你设置了一FOR循环。而include语句,是什么时候执行到了,什么把指定文件的内容代进来,继续执行。
  
include.php3:
  
  
    for($i=1;$i<=2;$i++){
     include("inc$i.inc");
  }
  echo $var1;
  echo $var2;
  echo 'inc1.inc文件中的$int变量值为' . $int . "!
";
  ?>
  
  

require.php3:
  
  
    for($i=1;$i<=2;$i++){
     require("inc$i.inc");
  }
  echo $var1;
  echo $var2;
  echo 'inc1.inc文件中的$int变量值为' . $int . "!
";
  ?>
  
  

inc1.inc:
    $var1 = "这是inc1.inc文件中的一个变量的值!
";
  if(isset($int)){
     $int++;
  }
  else{
     $int = 1;
  }
  ?>

inc2.inc:
    $var2 = "这是inc2.inc文件中的一个变量的值!
";
  ?>
Tags:





<?
$url="http://www.winliuxq.cn".$_SERVER["REQUEST_URI"];    
header("HTTP/1.1 301 Moved Permanently");    
header ("Location:$url");    
?>
Tags:

Base64之asp应用

[ 2008/06/10 10:03 | by selboo ]
加密函数:

<%const sbase_64_characters = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/"
function base64encode(byval ascontents)
dim lnposition
dim lsresult
dim char1
dim char2
dim char3
dim char4
dim byte1
dim byte2
dim byte3
dim savebits1
dim savebits2
dim lsgroupbinary
dim lsgroup64
if len(ascontents) mod 3 > 0 then ascontents = ascontents & string(3 - (len(ascontents) mod 3), " ")
lsresult = ""
for lnposition = 1 to len(ascontents) step 3
lsgroup64 = ""
lsgroupbinary = mid(ascontents, lnposition, 3)
byte1 = asc(mid(lsgroupbinary, 1, 1)): savebits1 = byte1 and 3
byte2 = asc(mid(lsgroupbinary, 2, 1)): savebits2 = byte2 and 15
byte3 = asc(mid(lsgroupbinary, 3, 1))
char1 = mid(sbase_64_characters, ((byte1 and 252) \ 4) + 1, 1)
char2 = mid(sbase_64_characters, (((byte2 and 240) \ 16) or (savebits1 * 16) and &hff) + 1, 1)
char3 = mid(sbase_64_characters, (((byte3 and 192) \ 64) or (savebits2 * 4) and &hff) + 1, 1)
char4 = mid(sbase_64_characters, (byte3 and 63) + 1, 1)
lsgroup64 = char1 & char2 & char3 & char4
lsresult = lsresult + lsgroup64
next
base64encode = lsresult
end function
response.write base64encode("abck")
%>

<%''''加密解密

' Functions to provide encoding/decoding of strings with Base64.
'
' Encoding: myEncodedString = base64_encode( inputString )
' Decoding: myDecodedString = base64_decode( encodedInputString )
'
' Programmed by Markus Hartsmar for ShameDesigns in 2002.
' Email me at: mark@shamedesigns.com
' Visit our website at: http://www.shamedesigns.com/
'

Dim Base64Chars
Base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" & _
"abcdefghijklmnopqrstuvwxyz" & _
"0123456789" & _
"+/"


' Functions for encoding string to Base64
Public Function base64_encode( byVal strIn )
Dim c1, c2, c3, w1, w2, w3, w4, n, strOut
For n = 1 To Len( strIn ) Step 3
c1 = Asc( Mid( strIn, n, 1 ) )
c2 = Asc( Mid( strIn, n + 1, 1 ) + Chr(0) )
c3 = Asc( Mid( strIn, n + 2, 1 ) + Chr(0) )
w1 = Int( c1 / 4 ) : w2 = ( c1 And 3 ) * 16 + Int( c2 / 16 )
If Len( strIn ) >= n + 1 Then
w3 = ( c2 And 15 ) * 4 + Int( c3 / 64 )
Else
w3 = -1
End If
If Len( strIn ) >= n + 2 Then
w4 = c3 And 63
Else
w4 = -1
End If
strOut = strOut + mimeencode( w1 ) + mimeencode( w2 ) + _
mimeencode( w3 ) + mimeencode( w4 )
Next
base64_encode = strOut
End Function

Private Function mimeencode( byVal intIn )
If intIn >= 0 Then
mimeencode = Mid( Base64Chars, intIn + 1, 1 )
Else
mimeencode = ""
End If
End Function


' Function to decode string from Base64
Public Function base64_decode( byVal strIn )
Dim w1, w2, w3, w4, n, strOut
For n = 1 To Len( strIn ) Step 4
w1 = mimedecode( Mid( strIn, n, 1 ) )
w2 = mimedecode( Mid( strIn, n + 1, 1 ) )
w3 = mimedecode( Mid( strIn, n + 2, 1 ) )
w4 = mimedecode( Mid( strIn, n + 3, 1 ) )
If w2 >= 0 Then _
strOut = strOut + _
Chr( ( ( w1 * 4 + Int( w2 / 16 ) ) And 255 ) )
If w3 >= 0 Then _
strOut = strOut + _
Chr( ( ( w2 * 16 + Int( w3 / 4 ) ) And 255 ) )
If w4 >= 0 Then _
strOut = strOut + _
Chr( ( ( w3 * 64 + w4 ) And 255 ) )
Next
base64_decode = strOut
End Function

Private Function mimedecode( byVal strIn )
If Len( strIn ) = 0 Then
mimedecode = -1 : Exit Function
Else
mimedecode = InStr( Base64Chars, strIn ) - 1
End If
End Function


%>


不能加密中文,对此做了一点修改,可以加密任何字符了,效率非常高

<%
OPTION EXPLICIT
const BASE_64_MAP_INIT = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
dim newline
dim Base64EncMap(63)
dim Base64DecMap(127)
'初始化函数
PUBLIC SUB initCodecs()
' 初始化变量
newline = "

" & chr(13) & chr(10)
dim max, idx
max = len(BASE_64_MAP_INIT)
for idx = 0 to max - 1
Base64EncMap(idx) = mid(BASE_64_MAP_INIT, idx + 1, 1)
next
for idx = 0 to max - 1
Base64DecMap(ASC(Base64EncMap(idx))) = idx
next
END SUB
'Base64加密函数
PUBLIC FUNCTION base64Encode(plain)
if len(plain) = 0 then
base64Encode = ""
exit function
end if
plain=enasc(plain)
dim ret, ndx, by3, first, second, third
by3 = (len(plain) \ 3) * 3
ndx = 1
do while ndx <= by3
first = asc(mid(plain, ndx+0, 1))
second = asc(mid(plain, ndx+1, 1))
third = asc(mid(plain, ndx+2, 1))
ret = ret & Base64EncMap( (first \ 4) AND 63 )
ret = ret & Base64EncMap( ((first * 16) AND 48) + ((second \ 16) AND 15 ) )
ret = ret & Base64EncMap( ((second * 4) AND 60) + ((third \ 64) AND 3 ) )
ret = ret & Base64EncMap( third AND 63)
ndx = ndx + 3
loop
if by3 < len(plain) then
first = asc(mid(plain, ndx+0, 1))
ret = ret & Base64EncMap( (first \ 4) AND 63 )
if (len(plain) MOD 3 ) = 2 then
second = asc(mid(plain, ndx+1, 1))
ret = ret & Base64EncMap( ((first * 16) AND 48) + ((second \ 16) AND 15 ) )
ret = ret & Base64EncMap( ((second * 4) AND 60) )
else
ret = ret & Base64EncMap( (first * 16) AND 48)
ret = ret '& "="
end if
ret = ret '& "="
end if
base64Encode = ret
END FUNCTION
'Base64解密函数
PUBLIC FUNCTION base64Decode(scrambled)
if len(scrambled) = 0 then
base64Decode = ""
exit function
end if
dim realLen
realLen = len(scrambled)
do while mid(scrambled, realLen, 1) = "="
realLen = realLen - 1
loop
dim ret, ndx, by4, first, second, third, fourth
ret = ""
by4 = (realLen \ 4) * 4
ndx = 1
do while ndx <= by4
first = Base64DecMap(asc(mid(scrambled, ndx+0, 1)))
second = Base64DecMap(asc(mid(scrambled, ndx+1, 1)))
third = Base64DecMap(asc(mid(scrambled, ndx+2, 1)))
fourth = Base64DecMap(asc(mid(scrambled, ndx+3, 1)))
ret = ret & chr( ((first * 4) AND 255) + ((second \ 16) AND 3))
ret = ret & chr( ((second * 16) AND 255) + ((third \ 4) AND 15))
ret = ret & chr( ((third * 64) AND 255) + (fourth AND 63))
ndx = ndx + 4
loop
if ndx < realLen then
first = Base64DecMap(asc(mid(scrambled, ndx+0, 1)))
second = Base64DecMap(asc(mid(scrambled, ndx+1, 1)))
ret = ret & chr( ((first * 4) AND 255) + ((second \ 16) AND 3))
if realLen MOD 4 = 3 then
third = Base64DecMap(asc(mid(scrambled,ndx+2,1)))
ret = ret & chr( ((second * 16) AND 255) + ((third \ 4) AND 15))
end if
end if
base64Decode = deasc(ret)
END FUNCTION

function enasc(str)
dim str_len,i,str_a,str_b,str_res
str_len=len(str)
if str_len<>0 then
for i=1 to str_len
str_a=mid(str,i,1)
str_b=ASC(str_a)
str_res=str_res & "," & str_b
next
end if
enasc=str_res
end function

function deasc(str)
dim str_len,i,str_a,str_b,str_res,str_v
str_len=len(str)
if str_len<>0 then
str_v=split(str,",")
for i=1 to ubound(str_v)
str_a=chr(str_v(i))
str_res=str_res & str_a
next
end if
deasc=str_res
end function

' 初始化
call initCodecs
' 测试代码
' dim inp, encode
' inp = "中国"
' response.write "加密前为:" & inp & newline
' encode = base64Encode(inp)
' response.write "加密后为:" & encode & newline
' response.write "解密后为:" & base64Decode(encode) & newline

%>

Tags:

什么是Base64,加密算法

[ 2008/06/10 10:02 | by selboo ]

什么是Base64?

按照RFC2045的定义, Base64被定义为:Base64内容传送编码被设计用来把任意序列的8位字节描述为一种不易被人直接识别的形式。(The Base64 Content-Transfer-Encoding is designed to represent arbitrary sequences of octets in a form that need not be humanly readable.)

图标base64编码在线转换器 :
http://www.motobit.com/util/base64-decoder-encoder.asp

Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一,在发送电子邮件时,服务器认证的用户名和密码需要用Base64编码,附件也需要用Base64编码。
下面简单介绍Base64算法的原理,由于代码太长就不在此贴出
Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一,大家可以查看RFC2045~RFC2049,上面有MIME的详细规范。

Base64要求把每三个8Bit的字节转换为四个6Bit的字节(3*8 = 4*6 = 24),然后把6Bit再添两位高位0,组成四个8Bit的字节,也就是说,转换后的字符串理论上将要比原来的长1/3。

这样说会不会太抽象了?不怕,我们来看一个例子:

转换前 aaaaaabb ccccdddd eeffffff
转换后 00aaaaaa 00bbcccc 00ddddee 00ffffff

应该很清楚了吧?上面的三个字节是原文,下面的四个字节是转换后的Base64编码,其前两位均为0。

转换后,我们用一个码表来得到我们想要的字符串(也就是最终的Base64编码),这个表是这样的:(摘自RFC2045)
Table 1: The Base64 Alphabet

Value Encoding Value Encoding Value Encoding Value Encoding
0 A 17 R 34 i 51 z
1 B 18 S 35 j 52 0
2 C 19 T 36 k 53 1
3 D 20 U 37 l 54 2
4 E 21 V 38 m 55 3
5 F 22 W 39 n 56 4
6 G 23 X 40 o 57 5
7 H 24 Y 41 p 58 6
8 I 25 Z 42 q 59 7
9 J 26 a 43 r 60 8
10 K 27 b 44 s 61 9
11 L 28 c 45 t 62 +
12 M 29 d 46 u 63 /
13 N 30 e 47 v
14 O 31 f 48 w (pad) =
15 P 32 g 49 x
16 Q 33 h 50 y
让我们再来看一个实际的例子,加深印象!

转换前 10101101 10111010 01110110
转换后 00101011 00011011 00101001 00110110
十进制 43 27 41 54
对应码表中的值 r b p 2


所以上面的24位编码,编码后的Base64值为 rbp2
解码同理,把 rbq2 的二进制位连接上再重组得到三个8位值,得出原码。
(解码只是编码的逆过程,在此我就不多说了,另外有关MIME的RFC还是有很多的,如果需要详细情况请自行查找。)

用更接近于编程的思维来说,编码的过程是这样的:

第一个字符通过右移2位获得第一个目标字符的Base64表位置,根据这个数值取到表上相应的字符,就是第一个目标字符。
然后将第一个字符左移4位加上第二个字符右移4位,即获得第二个目标字符。
再将第二个字符左移2位加上第三个字符右移6位,获得第三个目标字符。
最后取第三个字符的右6位即获得第四个目标字符。

在以上的每一个步骤之后,再把结果与 0x3F 进行 AND 位操作,就可以得到编码后的字符了。


C++ Base64编码/解码源代码


inline int Base64Encode(char * base64code, const char * src, int src_len = 0);
inline int Base64Decode(char * buf, const char * base64code, int src_len = 0);

以上两个函数内联定义在base64.h中,使用时include "base64.h" 即可,编码后的长度一般比原文多占1/3的存储空间,为了效率,程序并没有检查目标存储区是否溢出,请保证有足够的存储空间。


源码下载:http://www.yanghan.net/codes/base64src.rar

示例代码输出如下:
[Base64]:
xOO6w6OsU25haVgNCg0KoaGhodXiysfSu7j2QmFzZTY0tcSy4srU08q8/qOhDQoNCkJlc3QgV2lzaGVz
IQ0KDQqhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhICAgICAgICAgICAgICAgZVNYPyENCqGhoaGh
oaGhoaGhoaGhoaGhoaGhoaGhoaGhoaEgICAgICAgICAgICAgICBzbmFpeEB5ZWFoLm5ldA0KoaGhoaGh
oaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoSAgICAgICAgIDIwMDMtMTItMjU=

[源文]:
你好,SnaiX

  这是一个Base64的测试邮件!

Best Wishes!


最近在用加密后的二进制写cookie时碰到问题,cookie内容必须时可见字符,就必须将二进制文件转换成对应的可见字符,Base64编码是不错的解决方案。
1. 定义
Base64是用可见字符传输任意字节的编码方式。RFC2045的section 6.8有描述(The Base64 Content-Transfer-Encoding is designed to represent arbitrary sequences of octets in a form that need not be humanly readable)。电子邮件传输的编码就是采用Base64.

2. 如何编码
ASCII码表示范围0X00-0XFF,共255个字符,用一个字节(八位组)表示。Base64编码是用6位组来表示所有字符。-> 每三个8Bit的字节转换为四个6Bit的字节(3*8 = 4*6 = 24),然后把6Bit再添两位高位0,组成四个8Bit的字节,也就是说,转换后的字符串理论上将要比原来的长1/3。
来看一个转换的例子;
转换前 12345678 12345678 12345678
转换后 00123456 00781234 00567812 00345678

转换成Base64后,编码值范围0-63,共64个字符表示。如下:

Sequence Characters
0 … 25 ‘A’ … ’Z’
26 … 51 ‘a’ … ‘z’
52 … 61 ‘0’ … ‘9’
62 ‘+’
63 ‘/’

完整的映射如下:

The Base64 Alphabet

Value Encoding Value Encoding Value Encoding Value Encoding
0 A 17 R 34 i 51 z
1 B 18 S 35 j 52 0
2 C 19 T 36 k 53 1
3 D 20 U 37 l 54 2
4 E 21 V 38 m 55 3
5 F 22 W 39 n 56 4
6 G 23 X 40 o 57 5
7 H 24 Y 41 p 58 6
8 I 25 Z 42 q 59 7
9 J 26 a 43 r 60 8
10 K 27 b 44 s 61 9
11 L 28 c 45 t 62 +
12 M 29 d 46 u 63 /
13 N 30 e 47 v
14 O 31 f 48 w (pad) =
15 P 32 g 49 x
16 Q 33 h 50 y

填充符=。当需要编码的字符不是3的倍数,就会有余数1或2。这个时候就需要填充2位或1位来补齐,使转换后是4个字节,最多填充两个‘=’如:字符串“张”
11010101 HEX:D5 11000101 HEX:C5

00110101 00011100 00010100
十进制53 十进制34 十进制20 pad
字符’1’ 字符’i’ 字符’U’ 字符’=’

"张"转换成Base64就是"1iU=","张3"转换成Base64的结果是"1iU3"。

编码过程,在网上一篇文章大概是如下描述:

第一个字符通过右移2位获得第一个目标字符的Base64表位置,根据这个数值取到表上相应的字符,就是第一个目标字符。
然后将第一个字符左移4位加上第二个字符右移4位,即获得第二个目标字符。
再将第二个字符左移2位加上第三个字符右移6位,获得第三个目标字符。
最后取第三个字符的右6位即获得第四个目标字符。
在以上的每一个步骤之后,再把结果与 0x3F 进行 AND 位操作,就可以得到编码后的字符了。

如果原文字节数不是3的倍数,原文的字节不够的地方可以用全0来补足,转换时Base64编码用=号来代替。这就是为什么有些Base64编码会以一个或两个等号结束的原因,但等号最多只有两个。因为:

余数 = 原文字节数 MOD 3

所以余数任何情况下都只可能是0,1,2这三个数中的一个。如果余数是0的话,就表示原文字节数正好是3的倍数(最理想的情况啦)。如果是1的话,为了让Base64编码是4的倍数,就要补2个等号;同理,如果是2的话,就要补1个等号。

3. 源码实现

实现 1)

base.h

#include

std::string base64_encode(unsigned char const* , unsigned int len);
std::string base64_decode(std::string const& s);


base.cpp

#include "base64.h"
#include

static const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";


static inline bool is_base64(unsigned char c) {
return (isalnum(c) || (c == '+') || (c == '/'));
}

std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
std::string ret;
int i = 0;
int j = 0;
unsigned char char_array_3[3];
unsigned char char_array_4[4];

while (in_len--) {
char_array_3[i++] = *(bytes_to_encode++);
if (i == 3) {
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;

for(i = 0; (i <4) ; i++)
ret += base64_chars[char_array_4[i]];
i = 0;
}
}

if (i)
{
for(j = i; j < 3; j++)
char_array_3[j] = '\0';

char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;

for (j = 0; (j < i + 1); j++)
ret += base64_chars[char_array_4[j]];

while((i++ < 3))
ret += '=';

}

return ret;

}

std::string base64_decode(std::string const& encoded_string) {
int in_len = encoded_string.size();
int i = 0;
int j = 0;
int in_ = 0;
unsigned char char_array_4[4], char_array_3[3];
std::string ret;

while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
char_array_4[i++] = encoded_string[in_]; in_++;
if (i ==4) {
for (i = 0; i <4; i++)
char_array_4[i] = base64_chars.find(char_array_4[i]);

char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];

for (i = 0; (i < 3); i++)
ret += char_array_3[i];
i = 0;
}
}

if (i) {
for (j = i; j <4; j++)
char_array_4[j] = 0;

for (j = 0; j <4; j++)
char_array_4[j] = base64_chars.find(char_array_4[j]);

char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];

for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
}

return ret;
}


测试代码


#include "base64.h"
#include

int main() {
const std::string s = "ADP GmbH\nAnalyse Design & Programmierung\nGesellschaft mit beschränkter Haftung" ;

std::string encoded = base64_encode(reinterpret_cast(s.c_str()), s.length());
std::string decoded = base64_decode(encoded);

std::cout << "encoded: " << encoded << std::endl;
std::cout << "decoded: " << decoded << std::endl;

return 0;
}


实现 2)

类定义

class Base64
{
static char Encode(unsigned char uc);
static unsigned char Decode(char c);
static bool IsBase64(char c);
public:
static std::string Encode(
const std::vector & vby);
static std::vector Decode(
const std::string & str);
};


类实现


inline char Base64::Encode(unsigned char uc)
{
if (uc < 26)
{
return 'A'+uc;
}
if (uc < 52)
{
return 'a'+(uc-26);
}
if (uc < 62)
{
return '0'+(uc-52);
}
if (uc == 62)
{
return '+';
}
return '/';
};
inline unsigned char Base64::Decode(char c)
{
if (c >= 'A' && c <= 'Z')
{
return c - 'A';
}
if (c >= 'a' && c <= 'z')
{
return c - 'a' + 26;
}
if (c >= '0' && c <= '9')
{
return c - '0' + 52;
}
if (c == '+')
{
return 62;
};
return 63;
};
inline bool Base64::IsBase64(char c)
{
if (c >= 'A' && c <= 'Z')
{
return true;
}
if (c >= 'a' && c <= 'z')
{
return true;
}
if (c >= '0' && c <= '9')
{
return true;
}
if (c == '+')
{
return true;
};
if (c == '/')
{
return true;
};
if (c == '=')
{
return true;
};
return false;
};
inline std::string Base64::Encode(const std::vector & vby)
{
std::string retval;
if (vby.size() == 0)
{
return retval;
};
for (int i=0;i{
unsigned char by1=0,by2=0,by3=0;
by1 = vby[i];
if (i+1{
by2 = vby[i+1];
};
if (i+2{
by3 = vby[i+2];
}
unsigned char by4=0,by5=0,by6=0,by7=0;
by4 = by1>>2;
by5 = ((by1&0x3)<<4)|(by2>>4);
by6 = ((by2&0xf)<<2)|(by3>>6);
by7 = by3&0x3f;
retval += Encode(by4);
retval += Encode(by5);
if (i+1{
retval += Encode(by6);
}
else
{
retval += "=";
};
if (i+2{
retval += Encode(by7);
}
else
{
retval += "=";
};
if (i % (76/4*3) == 0)
{
retval += "\r\n";
}
};
return retval;
};
inline std::vector Base64::Decode(const std::string & _str)
{
std::string str;
for (int j=0;j<_str.length();j++)
{
if (IsBase64(_str[j]))
{
str += _str[j];
}
}
std::vector retval;
if (str.length() == 0)
{
return retval;
}
for (int i=0;i{
char c1='A',c2='A',c3='A',c4='A';
c1 = str[i];
if (i+1{
c2 = str[i+1];
};
if (i+2{
c3 = str[i+2];
};
if (i+3{
c4 = str[i+3];
};
unsigned char by1=0,by2=0,by3=0,by4=0;
by1 = Decode(c1);
by2 = Decode(c2);
by3 = Decode(c3);
by4 = Decode(c4);
retval.push_back( (by1<<2)|(by2>>4) );
if (c3 != '=')
{
retval.push_back( ((by2&0xf)<<4)|(by3>>2) );
}
if (c4 != '=')
{
retval.push_back( ((by3&0x3)<<6)|by4 );
};
};
return retval;
};
Tags:

PR算法

[ 2008/06/10 07:35 | by selboo ]

如果找友情连接 找这样的站

TPR= 他的PR

TLJ = 他的连接(友情)

以下内容只有回复后才可以浏览

PR=0.15+0.85*(TPR/TLJ)

换句话说

T=RR

TPR=TLJ*T

他的PR一定的前提下

连接越多 自己得到的PR越少

连接越少 自己得到的PR也就越多

TLJ反之.
Tags:
分页: 173/186 第一页 上页 168 169 170 171 172 173 174 175 176 177 下页 最后页 [ 显示模式: 摘要 | 列表 ]