Rc4 encrypt in PeopleSoft

起因: 经常我们会遇到url加密的情况。目前不管在国内国外关于peoplesoft 的资料是远远少于C# vb 等之类的资料的。

经过: 无奈之下只好自己了解rc4的加密原理自己写一个方法好了。

结果: 经过几天的折腾终于完成了。 代码如下。 如有疑问欢迎骚扰。

 

 Function IScript_RevengeBoy

   &Link = MsgGetExplainText(32000, 62, "Message Not Found");
   &sQuery = "http://home.cnblogs.com/RevengeBoy/";
   &Key = "uw*$2I5";
   Local array of any &s, &b16_map;
   &b16_digits = "0123456789abcdef";
   &b16_map = CreateArray();
   &result = CreateArray();
   &s = CreateArray();
  
   &times = 0;
   For &i3 = 0 To 255;
      If Mod(&i3, 16) = 0 And
            &i3 <> 0 And
            &i3 <> 255 Then
         &times = &times + 1;
      End-If;
      &charAtH1 = Substring(&b16_digits, &times + 1, 1);
      &charAtH2 = Substring(&b16_digits, Mod(&i3, 16) + 1, 1);
      &b16_map [&i3 + 1] = &charAtH1 | &charAtH2;
      rem %Response.Write("i=" | &i3 | "times=" | &times | ",    Mod(&i3, 15)=" | Mod(&i3, 16) | "<br>");
     
      rem %Response.Write("&b16_map [" | (&i3 + 1) | "] =" | &charAtH1 | &charAtH2 | "<br>");
      &map = &charAtH1 | &charAtH2;
      rem %Response.Write(&map);
   End-For;
  
  
   For &i0 = 1 To 256;
      &s [&i0] = &i0 - 1;
   End-For;
  
   &j = 0;
   &x = 0;
   For &i = 0 To 255;
      &charAtX = Substring(&Key, Mod(&i, Len(&Key)) + 1, 1);
      &j = Mod((&j + &s [&i + 1] + Code(&charAtX)), 256);
      &x = &s [&i + 1];
      &s [&i + 1] = &s [&j + 1];
      &s [&j + 1] = &x;
   End-For;
  
   &i2 = 0;
   &j = 0;
   &ct = "";
   &str = "";
   For &y = 0 To Len(&sQuery) - 1;
      &i2 = Mod((&i2 + 1), 256);
      &j = Mod((&j + &s [&i2 + 1]), 256);
      &x = &s [&i2 + 1];
      &s [&i2 + 1] = &s [&j + 1];
      &s [&j + 1] = &x;
      &charAtY = Substring(&sQuery, &y + 1, 1);
      &Char1 = Code(&charAtY);
      &Char2 = &s [Mod((&s [&i2 + 1] + &s [&j + 1]), 256) + 1];
      SQLExec(" select (" | &Char1 | "  +  " | &Char2 | ")   -   BITAND(" | &Char1 | "," | &Char2 | ")   *   2  from   dual", &str);
      &ct = &ct | &b16_map [&str + 1];

   End-For;
rem reuslt
%Response.Write(&Link | "w" | &ct);
  
End-Function;

 

 

posted on 2010-12-02 19:18  RevengeBoy  阅读(384)  评论(0编辑  收藏  举报

导航