VB 加密与解密的程序代码

VB 加密与解密的程序代码,第1张

加密:

Private Function JiaMi(ByVal varPass As String) As String '参数varPass是需要加密的文本内容

Dim varJiaMi As String * 20

Dim varTmp As Double

Dim strJiaMi As String

Dim I

For I = 1 To Len(varPass)

varTmp = AscW(Mid$(varPass, I, 1))

varJiaMi = Str$(((((varTmp * 1.5) / 5.6) * 2.7) * I))

strJiaMi = strJiaMi &varJiaMi

Next I

JiaMi = strJiaMi

End Function

解密函数

Private Function JieMi(ByVal varPass As String) As String '参数varPass是需要解密的密文内容

Dim varReturn As String * 20

Dim varConvert As Double

Dim varFinalPass As String

Dim varKey As Integer

Dim varPasslenth As Long

varPasslenth = Len(varPass)

For I = 1 To varPasslenth / 20

varReturn = Mid(varPass, (I - 1) * 20 + 1, 20)

varConvert = Val(Trim(varReturn))

varConvert = ((((varConvert / 1.5) * 5.6) / 2.7) / I)

varFinalPass = varFinalPass &ChrW(Val(varConvert))

Next I

JieMi = varFinalPass

End Function

扩展资料:

注意事项

编写加密程序,将用户输入的一个英文句子加密为加密字符串,然后输出加密字符串。假设句子长度不超过100个字符。

根据给定的句子加密函数原型SentenceEncoding,编写函数SentenceEncoding调用给定的字符加密函数CharEncoding完成句子加密。

然后,编写主程序提示用户输入英文句子,然后调用函数SentenceEncoding对句子加密,最后输出加密后的句子。

字符加密规则为大写蔽铅字母和改禅小写字母均加密为其补码, 我们定义ASCII码值相加为’A’+’Z’即155的两个大写字母互为补码,ASCII码值相加为’a’+’z’即219的两个小写字母互为补码。

空格用@代替,句号以#代替,其它字符用句点代宏歼好替。

函数原型:

void SentenceEncoding(char *soure,char *code)

功能:对待加密字符串source加密后保存加密字符串到code.

参数:char *soure,指向待加密句子的字符串指针;

char *code 指向加密字符串的字符串指针;

字符加密函数代码。

有几个地方要注意:

1、VB中的三角函数的角度全部是用弧度制表示的,如果是度数的话陵首,应先乘以180再除以π转成弧度,再用函数计算结果。

2、VB中直接支持的三角函数有:Sin()、Cos()、Tan(),如果涉及到其它三角函数,可以从下面列出的代码中自己选择相应的函数:

Function

Sec(X)

As

Double

'正割

Sec

=

1

/

Cos(Angle)

End

Function

Function

Csc(X)

As

Double

'余割

Csc

=

1

/

Sin(Angle)

End

Function

Function

Cot(X)

As

Double

'余切

Cot

=

1

/

Tan(Angle)

End

Function

Function

ArcSin(X)

As

Double

'反正弦

ArcSin

=

Atn(X

/

Sqr(-X

*

X

+

1))

End

Function

Function

ArcCos(X)

As

Double

'反余弦

ArcCos

=

Atn(-X

/

Sqr(-X

*

X

+

1))

+

2

*

Atn(1)

End

Function

Function

ArcSec(X)

As

Double

'反正割

ArcSec

=

Atn(X

/

Sqr(X

*

X

-

1))

+

Sgn((X)

-

1)

*

(2

*

Atn(1))

End

Function

Function

ArcCsc(X)

As

Double

'反余割

ArcCsc

=

Atn(X

/

Sqr(X

*

X

-

1))

+

(Sgn(X)

-

1)

*

(2

*

Atn(1))

End

Function

Function

ArcCot(X)

As

Double

'反余切

ArcCot

=

Atn(X)

+

2

*

Atn(1)

End

Function

Function

HSin(X)

As

Double

'双曲正弦

HSin

=

(Exp(X)

-

Exp(-X))

/

2

End

Function

Function

HCos(X)

As

Double

'双曲余弦

HCos

=

(Exp(X)

+

Exp(-X))

/

2

End

Function

Function

HTan(X)

As

Double

'双曲正切

HTan

=

(Exp(X)

-

Exp(-X))

/

(Exp(X)

+

Exp(-X))

End

Function

Function

HSec(X)

As

Double

'双曲正割

HSec

=

2

/

(Exp(X)

+

Exp(-X))

End

Function

Function

HCsc(X)

As

Double

'双曲余割

HCsc

=

2

/

(Exp(X)

-

Exp(-X))

End

Function

Function

HCot(X)

As

Double

'双旦汪祥曲余切

HCot

=

(Exp(X)

+

Exp(-X))

/

(Exp(X)

-

Exp(-X))

End

Function

Function

HArcsin(X)

As

Double

'反双曲正弦

HArcsin

=

Log(X

+

Sqr(X

*

X

+

1))

End

Function

Function

HArccos(X)

As

Double

'反双曲余弦

HArccos

=

Log(X

+

Sqr(X

*

X

-

1))

End

Function

Function

HArctan(X)

As

Double

'反双曲正切

HArctan

=

Log((1

+

X)

/

(1

-

X))

/

2

End

Function

Function

HArcsec(X)

As

Double

'反双曲正割

HArcsec

=

Log((Sqr(-X

*

X

+

1)

+

1)

/

X)

End

Function

Function

HArccsc(X)

As

Double

'反双曲模搏余割

HArccsc

=

Log((Sgn(X)

*

Sqr(X

*

X

+

1)

+

1)

/

X)

End

Function

Function

HArccot(X)

As

Double

'反双曲余切

HArccot

=

Log((X

+

1)

/

(X

-

1))

/

2

End

Function

用途:将十进制转化为二 进 制

' 输入:Dec(十进制数)

' 输入数据类型:Long

' 输出:DEC_to_BIN(二 进 制数)

' 输出数据类型团手轮:String

' 输入的最大数为2147483647,输出最薯差大数为1111111111111111111111111111111(31个1)

Public Function DEC_to_BIN(Byval Dec As Long) As String

DEC_to_BIN = ""

Do While Dec >0

DEC_to_BIN = Dec Mod 2 &DEC_to_BIN

Dec = Dec \ 2

Loop

End Function

Private Sub Command1_Click()

Dim a As String

Dim b As Long 'b是你要转换的数塌信

a = DEC_to_BIN(b)

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12447580.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存