乙個簡單的加密 解密方法

2021-03-31 18:49:12 字數 2358 閱讀 8008

private function encryptstring(strstring)

dim charhexset, intstringlen, strtemp, strraw, i, intkey, intoffset

randomize timer

intkey = round((rnd * 1000000) + 1000000) '##### key bitsize

intoffset = round((rnd * 1000000) + 1000000) '##### keyoffset bitsize

if isnull(strstring) = false then

strraw = strstring

intstringlen = len(strraw)

for i = 0 to intstringlen - 1

strtemp = left(strraw, 1)

strraw = right(strraw, len(strraw) - 1)

charhexset = charhexset & hex(asc(strtemp) * intkey)& hex(intkey)

next

encryptstring = charhexset & "|" & hex(intoffset + intkey) & "|" & hex(intoffset)

else

encryptstring = ""

end if

end function

private function decryptstring(strcryptstring)

dim strraw, arhexcharset, i, intkey, intoffset, strrawkey, strhexcrypdata

strrawkey = right(strcryptstring, len(strcryptstring) - instr(strcryptstring, "|"))

intoffset = right(strrawkey, len(strrawkey) - instr(strrawkey,"|"))

intkey = hexconv(left(strrawkey, instr(strrawkey, "|") - 1)) - hexconv(intoffset)

strhexcrypdata = left(strcryptstring, len(strcryptstring) - (len(strrawkey) + 1))

arhexcharset = split(strhexcrypdata, hex(intkey))

for i=0 to ubound(arhexcharset)

strraw = strraw & chr(hexconv(arhexcharset(i))/intkey)

next

decryptstring = strraw

end function

private function hexconv(hexvar)

dim hxx, hxx_var, multiply

if hexvar <> "" then

hexvar = ucase(hexvar)

hexvar = strreverse(hexvar)

dim hx()

redim hx(len(hexvar))

hxx = 0

hxx_var = 0

for hxx = 1 to len(hexvar)

if multiply = "" then multiply = 1

hx(hxx) = mid(hexvar,hxx,1)

hxx_var = (get_hxno(hx(hxx)) * multiply) + hxx_var

multiply = (multiply * 16)

next

hexvar = hxx_var

hexconv = hexvar

end if

end function

private function get_hxno(ghx)

if ghx = "a" then

ghx = 10

elseif ghx = "b" then

ghx = 11

elseif ghx = "c" then

ghx = 12

elseif ghx = "d" then

ghx = 13

elseif ghx = "e" then

ghx = 14

elseif ghx = "f" then

ghx = 15

end if

get_hxno = ghx

end function

乙個簡單的XOR加密方法

主要用來加密流資料,因為aes太慢需求也不需要很重的加密,所有選擇用xor加密,但是發現乙個問題,就是加密內容是一竄json都是以 開頭,xor加密太簡單導致很容易就猜出密碼,所以改進了一下,用key的ascii碼合計做開頭位置開頭位移,以及最後反覆多次加密來解決 加密 key金鑰 data資料 f...

關於加密解密的乙個問題

關於加密解密的乙個問題 delphi windows sdk api 演算法想實現這麼個功能 加密 根據10位數的數字編號如 1000000001 加上數字key後,產生一串8位數的數字編號 解密 解密就是把8位數數字編號還原成10的 請各位高手幫忙,分不夠可以再給 大家幫幫忙啊 程式自己寫,給你說...

又乙個php加密和解密的方法

之前的文章 php openssl加密解密方法 今天又看到乙個加密和解密的方法,記錄一下 function encrypt data,key char key x for i 0 i len i ord char 256 return base64 encode str function decry...