代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
ActionScript
】
AS2的base64函数
作者:
/ 发布于
2011/1/3
/
2096
<div> <table style="font-family: monospace" class="actionscript codes"> <tbody> <tr class="li1"> <td style="line-height: 150%; font-family: Verdana, Monospace; font-size: 12px; font-weight: bold; margin-right: 10px"> <pre style="line-height: 150%; font-family: Verdana, Monospace; font-size: 12px; font-weight: bold; margin-right: 10px"><span style="font-style: italic; color: #808080">/**</span> <span style="font-style: italic; color: #808080">* Decodes a base64 string</span> <span style="font-style: italic; color: #808080">*/</span> <span style="color: #0000ff">function</span> decode<span style="color: #66cc66">(</span>src:<span style="color: blue">String</span><span style="color: #66cc66">)</span>:<span style="color: blue">String</span> <span style="color: #66cc66">{</span> <span style="color: #0000ff">var</span> base64chars:<span style="color: blue">String</span> = <span style="color: #ff0000">"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="</span>; <span style="color: #0000ff">var</span> i:<span style="color: blue">Number</span> = <span style="color: #cc66cc">0</span>; <span style="color: #0000ff">var</span> output:<span style="color: blue">String</span> = <span style="color: #0000ff">new</span> <span style="color: blue">String</span><span style="color: #66cc66">(</span><span style="color: #ff0000">""</span><span style="color: #66cc66">)</span>; <span style="color: #0000ff">var</span> chr1:<span style="color: blue">Number</span>, chr2:<span style="color: blue">Number</span>, chr3:<span style="color: blue">Number</span>; <span style="color: #0000ff">var</span> enc1:<span style="color: blue">Number</span>, enc2:<span style="color: blue">Number</span>, enc3:<span style="color: blue">Number</span>, enc4:<span style="color: blue">Number</span>; <span style="color: #0099cc">while</span> <span style="color: #66cc66">(</span>i<span style="color: #66cc66"><</span>src.<span style="color: blue">length</span><span style="color: #66cc66">)</span> <span style="color: #66cc66">{</span> enc1 = base64chars.<span style="color: blue">indexOf</span><span style="color: #66cc66">(</span>src.<span style="color: blue">charAt</span><span style="color: #66cc66">(</span>i++<span style="color: #66cc66">)</span><span style="color: #66cc66">)</span>; enc2 = base64chars.<span style="color: blue">indexOf</span><span style="color: #66cc66">(</span>src.<span style="color: blue">charAt</span><span style="color: #66cc66">(</span>i++<span style="color: #66cc66">)</span><span style="color: #66cc66">)</span>; enc3 = base64chars.<span style="color: blue">indexOf</span><span style="color: #66cc66">(</span>src.<span style="color: blue">charAt</span><span style="color: #66cc66">(</span>i++<span style="color: #66cc66">)</span><span style="color: #66cc66">)</span>; enc4 = base64chars.<span style="color: blue">indexOf</span><span style="color: #66cc66">(</span>src.<span style="color: blue">charAt</span><span style="color: #66cc66">(</span>i++<span style="color: #66cc66">)</span><span style="color: #66cc66">)</span>; chr1 = <span style="color: #66cc66">(</span>enc1 <span style="color: #66cc66"><<</span> <span style="color: #cc66cc">2</span><span style="color: #66cc66">)</span> <span style="color: #66cc66">|</span> <span style="color: #66cc66">(</span>enc2 <span style="color: #66cc66">>></span> <span style="color: #cc66cc">4</span><span style="color: #66cc66">)</span>; chr2 = <span style="color: #66cc66">(</span><span style="color: #66cc66">(</span>enc2 <span style="color: #66cc66">&</span> <span style="color: #cc66cc">15</span><span style="color: #66cc66">)</span> <span style="color: #66cc66"><<</span> <span style="color: #cc66cc">4</span><span style="color: #66cc66">)</span> <span style="color: #66cc66">|</span> <span style="color: #66cc66">(</span>enc3 <span style="color: #66cc66">>></span> <span style="color: #cc66cc">2</span><span style="color: #66cc66">)</span>; chr3 = <span style="color: #66cc66">(</span><span style="color: #66cc66">(</span>enc3 <span style="color: #66cc66">&</span> <span style="color: #cc66cc">3</span><span style="color: #66cc66">)</span> <span style="color: #66cc66"><<</span> <span style="color: #cc66cc">6</span><span style="color: #66cc66">)</span> <span style="color: #66cc66">|</span> enc4; output += <span style="color: blue">String</span>.<span style="color: blue">fromCharCode</span><span style="color: #66cc66">(</span>chr1<span style="color: #66cc66">)</span>; <span style="color: #0099cc">if</span> <span style="color: #66cc66">(</span>enc3 <span style="color: #66cc66">!</span>= <span style="color: #cc66cc">64</span><span style="color: #66cc66">)</span> <span style="color: #66cc66">{</span> output = output+<span style="color: blue">String</span>.<span style="color: blue">fromCharCode</span><span style="color: #66cc66">(</span>chr2<span style="color: #66cc66">)</span>; <span style="color: #66cc66">}</span> <span style="color: #0099cc">if</span> <span style="color: #66cc66">(</span>enc4 <span style="color: #66cc66">!</span>= <span style="color: #cc66cc">64</span><span style="color: #66cc66">)</span> <span style="color: #66cc66">{</span> output = output+<span style="color: blue">String</span>.<span style="color: blue">fromCharCode</span><span style="color: #66cc66">(</span>chr3<span style="color: #66cc66">)</span>; <span style="color: #66cc66">}</span> <span style="color: #66cc66">}</span> <span style="color: #0099cc">return</span> utf8to16<span style="color: #66cc66">(</span>output<span style="color: #66cc66">)</span>; <span style="color: #66cc66">}</span> <span style="color: #0000ff">function</span> utf16to8<span style="color: #66cc66">(</span>str<span style="color: #66cc66">)</span>:<span style="color: blue">String</span> <span style="color: #66cc66">{</span> <span style="color: #0000ff">var</span> out, i, len, c; out = <span style="color: #ff0000">""</span>; len = str.<span style="color: blue">length</span>; <span style="color: #0099cc">for</span> <span style="color: #66cc66">(</span>i=<span style="color: #cc66cc">0</span>; i<span style="color: #66cc66"><</span>len; i++<span style="color: #66cc66">)</span> <span style="color: #66cc66">{</span> c = str.<span style="color: blue">charCodeAt</span><span style="color: #66cc66">(</span>i<span style="color: #66cc66">)</span>; <span style="color: #0099cc">if</span> <span style="color: #66cc66">(</span><span style="color: #66cc66">(</span>c<span style="color: #66cc66">></span>=0x0001<span style="color: #66cc66">)</span> <span style="color: #66cc66">&&</span> <span style="color: #66cc66">(</span>c<span style="color: #66cc66"><</span>=0x007F<span style="color: #66cc66">)</span><span style="color: #66cc66">)</span> <span style="color: #66cc66">{</span> out += str.<span style="color: blue">charAt</span><span style="color: #66cc66">(</span>i<span style="color: #66cc66">)</span>; <span style="color: #66cc66">}</span> <span style="color: #0099cc">else</span> <span style="color: #0099cc">if</span> <span style="color: #66cc66">(</span>c<span style="color: #66cc66">></span>0x07FF<span style="color: #66cc66">)</span> <span style="color: #66cc66">{</span> out += <span style="color: blue">String</span>.<span style="color: blue">fromCharCode</span><span style="color: #66cc66">(</span>0xE0 <span style="color: #66cc66">|</span> <span style="color: #66cc66">(</span><span style="color: #66cc66">(</span>c <span style="color: #66cc66">>></span> <span style="color: #cc66cc">12</span><span style="color: #66cc66">)</span> <span style="color: #66cc66">&</span> 0x0F<span style="color: #66cc66">)</span><span style="color: #66cc66">)</span>; out += <span style="color: blue">String</span>.<span style="color: blue">fromCharCode</span><span style="color: #66cc66">(</span>0x80 <span style="color: #66cc66">|</span> <span style="color: #66cc66">(</span><span style="color: #66cc66">(</span>c <span style="color: #66cc66">>></span> <span style="color: #cc66cc">6</span><span style="color: #66cc66">)</span> <span style="color: #66cc66">&</span> 0x3F<span style="color: #66cc66">)</span><span style="color: #66cc66">)</span>; out += <span style="color: blue">String</span>.<span style="color: blue">fromCharCode</span><span style="color: #66cc66">(</span>0x80 <span style="color: #66cc66">|</span> <span style="color: #66cc66">(</span><span style="color: #66cc66">(</span>c <span style="color: #66cc66">>></span> <span style="color: #cc66cc">0</span><span style="color: #66cc66">)</span> <span style="color: #66cc66">&</span> 0x3F<span style="color: #66cc66">)</span><span style="color: #66cc66">)</span>; <span style="color: #66cc66">}</span> <span style="color: #0099cc">else</span> <span style="color: #66cc66">{</span> out += <span style="color: blue">String</span>.<span style="color: blue">fromCharCode</span><span style="color: #66cc66">(</span>0xC0 <span style="color: #66cc66">|</span> <span style="color: #66cc66">(</span><span style="color: #66cc66">(</span>c <span style="color: #66cc66">>></span> <span style="color: #cc66cc">6</span><span style="color: #66cc66">)</span> <span style="color: #66cc66">&</span> 0x1F<span style="color: #66cc66">)</span><span style="color: #66cc66">)</span>; out += <span style="color: blue">String</span>.<span style="color: blue">fromCharCode</span><span style="color: #66cc66">(</span>0x80 <span style="color: #66cc66">|</span> <span style="color: #66cc66">(</span><span style="color: #66cc66">(</span>c <span style="color: #66cc66">>></span> <span style="color: #cc66cc">0</span><span style="color: #66cc66">)</span> <span style="color: #66cc66">&</span> 0x3F<span style="color: #66cc66">)</span><span style="color: #66cc66">)</span>; <span style="color: #66cc66">}</span> <span style="color: #66cc66">}</span> <span style="color: #0099cc">return</span> out; <span style="color: #66cc66">}</span> <span style="color: #0000ff">function</span> utf8to16<span style="color: #66cc66">(</span>str<span style="color: #66cc66">)</span>:<span style="color: blue">String</span> <span style="color: #66cc66">{</span> <span style="color: #0000ff">var</span> out, i, len, c; <span style="color: #0000ff">var</span> char2, char3; out = <span style="color: #ff0000">""</span>; len = str.<span style="color: blue">length</span>; i = <span style="color: #cc66cc">0</span>; <span style="color: #0099cc">while</span> <span style="color: #66cc66">(</span>i<span style="color: #66cc66"><</span>len<span style="color: #66cc66">)</span> <span style="color: #66cc66">{</span> c = str.<span style="color: blue">charCodeAt</span><span style="color: #66cc66">(</span>i++<span style="color: #66cc66">)</span>; <span style="color: #0099cc">switch</span> <span style="color: #66cc66">(</span>c <span style="color: #66cc66">>></span> <span style="color: #cc66cc">4</span><span style="color: #66cc66">)</span> <span style="color: #66cc66">{</span> <span style="color: #0099cc">case</span> <span style="color: #cc66cc">0</span> : <span style="color: #0099cc">case</span> <span style="color: #cc66cc">1</span> : <span style="color: #0099cc">case</span> <span style="color: #cc66cc">2</span> : <span style="color: #0099cc">case</span> <span style="color: #cc66cc">3</span> : <span style="color: #0099cc">case</span> <span style="color: #cc66cc">4</span> : <span style="color: #0099cc">case</span> <span style="color: #cc66cc">5</span> : <span style="color: #0099cc">case</span> <span style="color: #cc66cc">6</span> : <span style="color: #0099cc">case</span> <span style="color: #cc66cc">7</span> : out += str.<span style="color: blue">charAt</span><span style="color: #66cc66">(</span>i-<span style="color: #cc66cc">1</span><span style="color: #66cc66">)</span>; <span style="color: #0099cc">break</span>; <span style="color: #0099cc">case</span> <span style="color: #cc66cc">12</span> : <span style="color: #0099cc">case</span> <span style="color: #cc66cc">13</span> : char2 = str.<span style="color: blue">charCodeAt</span><span style="color: #66cc66">(</span>i++<span style="color: #66cc66">)</span>; out += <span style="color: blue">String</span>.<span style="color: blue">fromCharCode</span><span style="color: #66cc66">(</span><span style="color: #66cc66">(</span><span style="color: #66cc66">(</span>c <span style="color: #66cc66">&</span> 0x1F<span style="color: #66cc66">)</span> <span style="color: #66cc66"><<</span> <span style="color: #cc66cc">6</span><span style="color: #66cc66">)</span> <span style="color: #66cc66">|</span> <span style="color: #66cc66">(</span>char2 <span style="color: #66cc66">&</span> 0x3F<span style="color: #66cc66">)</span><span style="color: #66cc66">)</span>; <span style="color: #0099cc">break</span>; <span style="color: #0099cc">case</span> <span style="color: #cc66cc">14</span> : char2 = str.<span style="color: blue">charCodeAt</span><span style="color: #66cc66">(</span>i++<span style="color: #66cc66">)</span>; char3 = str.<span style="color: blue">charCodeAt</span><span style="color: #66cc66">(</span>i++<span style="color: #66cc66">)</span>; out += <span style="color: blue">String</span>.<span style="color: blue">fromCharCode</span><span style="color: #66cc66">(</span><span style="color: #66cc66">(</span><span style="color: #66cc66">(</span>c <span style="color: #66cc66">&</span> 0x0F<span style="color: #66cc66">)</span> <span style="color: #66cc66"><<</span> <span style="color: #cc66cc">12</span><span style="color: #66cc66">)</span> <span style="color: #66cc66">|</span> <span style="color: #66cc66">(</span><span style="color: #66cc66">(</span>char2 <span style="color: #66cc66">&</span> 0x3F<span style="color: #66cc66">)</span> <span style="color: #66cc66"><<</span> <span style="color: #cc66cc">6</span><span style="color: #66cc66">)</span> <span style="color: #66cc66">|</span> <span style="color: #66cc66">(</span><span style="color: #66cc66">(</span>char3 <span style="color: #66cc66">&</span> 0x3F<span style="color: #66cc66">)</span> <span style="color: #66cc66"><<</span> <span style="color: #cc66cc">0</span><span style="color: #66cc66">)</span><span style="color: #66cc66">)</span>; <span style="color: #0099cc">break</span>; <span style="color: #66cc66">}</span> <span style="color: #66cc66">}</span> <span style="color: #0099cc">return</span> out; <span style="color: #66cc66">}</span></pre> </td> </tr> </tbody> </table> </div>
试试其它关键字
base64
同语言下
.
从网络服务器上下载DLL文件
.
flex音乐播放器
.
关机小脚本
.
Flash获取当前文件名、路径名
.
按中文字母排序
.
AS3 混淆加密
.
中国象棋博弈树搜索算法
.
获得当前flash文件加载的URL
.
AS2寻路算法
.
AS3中使用摄像头
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
贡献的其它代码
Label
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3