当前位置: 高中信息技术 / 综合题
  • 1. (2020·浙江模拟) 维吉尼亚(Vigenere)密码。如下图所示,分别用行和列表示待加密的字符(明文)和当前字符的密钥,行和列的交叉点的字符即为加密后的结果(密文)。在加密时,密文与明文的字母大小写形式保持一致,如,明文字母为大写,则加密后的密文字母也为大写;当密钥长度不足时重复使用密钥。例如:当明文M=HelloWorld,密钥K=abc时,密文C=HfnlpYosnd。运算过程如下所示:

    明文:HelloWorld

    密钥:abcabcabca

    密文:HfnlpYosnd

    A

    B

    C

    D

    E

    F

    G

    H

    I

    J

    K

    L

    M

    N

    O

    P

    Q

    R

    S

    T

    U

    V

    W

    X

    Y

    Z

    A

    A

    B

    C

    D

    E

    F

    G

    H

    I

    J

    K

    L

    M

    N

    O

    P

    Q

    R

    S

    T

    U

    V

    W

    X

    Y

    Z

    B

    B

    C

    D

    E

    F

    G

    H

    I

    J

    K

    L

    M

    N

    O

    P

    Q

    R

    S

    T

    U

    V

    W

    X

    Y

    Z

    A

    C

    C

    D

    E

    F

    G

    H

    I

    J

    K

    L

    M

    N

    O

    P

    Q

    R

    S

    T

    U

    V

    W

    X

    Y

    Z

    A

    B

    D

    D

    E

    F

    G

    H

    I

    J

    K

    L

    M

    N

    O

    P

    Q

    R

    S

    T

    U

    V

    W

    X

    Y

    Z

    A

    B

    C

    E

    E

    F

    G

    H

    I

    J

    K

    L

    M

    N

    O

    P

    Q

    R

    S

    T

    U

    V

    W

    X

    Y

    Z

    A

    B

    C

    D

    F

    F

    G

    H

    I

    J

    K

    L

    M

    N

    O

    P

    Q

    R

    S

    T

    U

    V

    W

    X

    Y

    Z

    A

    B

    C

    D

    E

    G

    G

    H

    I

    J

    K

    L

    M

    N

    O

    P

    Q

    R

    S

    T

    U

    V

    W

    X

    Y

    Z

    A

    B

    C

    D

    E

    F

    H

    H

    I

    J

    K

    L

    M

    N

    O

    P

    Q

    R

    S

    T

    U

    V

    W

    X

    Y

    Z

    A

    B

    C

    D

    E

    F

    G

    I

    I

    J

    K

    L

    M

    N

    O

    P

    Q

    R

    S

    T

    U

    V

    W

    X

    Y

    Z

    A

    B

    C

    D

    E

    F

    G

    H

    J

    J

    K

    L

    M

    N

    O

    P

    Q

    R

    S

    T

    U

    V

    W

    X

    Y

    Z

    A

    B

    C

    D

    E

    F

    G

    H

    I

    K

    K

    L

    M

    N

    O

    P

    Q

    R

    S

    T

    U

    V

    W

    X

    Y

    Z

    A

    B

    C

    D

    E

    F

    G

    H

    I

    J

    L

    L

    M

    N

    O

    P

    Q

    R

    S

    T

    U

    V

    W

    X

    Y

    Z

    A

    B

    C

    D

    E

    F

    G

    H

    I

    J

    K

    M

    M

    N

    O

    P

    Q

    R

    S

    T

    U

    V

    W

    X

    Y

    Z

    A

    B

    C

    D

    E

    F

    G

    H

    I

    J

    K

    L

    N

    N

    O

    P

    Q

    R

    S

    T

    U

    V

    W

    X

    Y

    Z

    A

    B

    C

    D

    E

    F

    G

    H

    I

    J

    K

    L

    M

    O

    O

    P

    Q

    R

    S

    T

    U

    V

    W

    X

    Y

    Z

    A

    B

    C

    D

    E

    F

    G

    H

    I

    J

    K

    L

    M

    N

    P

    P

    Q

    R

    S

    T

    U

    V

    W

    X

    Y

    Z

    A

    B

    C

    D

    E

    F

    G

    H

    I

    J

    K

    L

    M

    N

    O

    Q

    Q

    R

    S

    T

    U

    V

    W

    X

    Y

    Z

    A

    B

    C

    D

    E

    F

    G

    H

    I

    J

    K

    L

    M

    N

    O

    P

    R

    R

    S

    T

    U

    V

    W

    X

    Y

    Z

    A

    B

    C

    D

    E

    F

    G

    H

    I

    J

    K

    L

    M

    N

    O

    P

    Q

    S

    S

    T

    U

    V

    W

    X

    Y

    Z

    A

    B

    C

    D

    E

    F

    G

    H

    I

    J

    K

    L

    M

    N

    O

    P

    Q

    R

    T

    T

    U

    V

    W

    X

    Y

    Z

    A

    B

    C

    D

    E

    F

    G

    H

    I

    J

    K

    L

    M

    N

    O

    P

    Q

    R

    S

    U

    U

    V

    W

    X

    Y

    Z

    A

    B

    C

    D

    E

    F

    G

    H

    I

    J

    K

    L

    M

    N

    O

    P

    Q

    R

    S

    T

    V

    V

    W

    X

    Y

    Z

    A

    B

    C

    D

    E

    F

    G

    H

    I

    J

    K

    L

    M

    N

    O

    P

    Q

    R

    S

    T

    U

    W

    W

    X

    Y

    Z

    A

    B

    C

    D

    E

    F

    G

    H

    I

    J

    K

    L

    M

    N

    O

    P

    Q

    R

    S

    T

    U

    V

    X

    X

    Y

    Z

    A

    B

    C

    D

    E

    F

    G

    H

    I

    J

    K

    L

    M

    N

    O

    P

    Q

    R

    S

    T

    U

    V

    W

    Y

    Y

    Z

    A

    B

    C

    D

    E

    F

    G

    H

    I

    J

    K

    L

    M

    N

    O

    P

    Q

    R

    S

    T

    U

    V

    W

    X

    Z

    Z

    A

    B

    C

    D

    E

    F

    G

    H

    I

    J

    K

    L

    M

    N

    O

    P

    Q

    R

    S

    T

    U

    V

    W

    X

    Y

    依据上述算法描述设计了如下VB程序。请回答下列问题:

    1. (1) 若明文是Jia,密钥是Pass,则输出的密文是:
    2. (2) 请在横线处填上合适的代码。

      Const MIN_ASC = 65       ′字母“A”的ASCII值

      Function X2D(x As String) As String     ′字符串小写转成大写

      Dim s As String, zf As String, i As Integer

      s = “”

      For i = 1 To Len(x)

      zf = Mid(x, i, 1)

      If zf >= “a” And zf <= “z” Then

                  s = s +

      Else

            s = s + zf
                End If
          Next i
          X2D = s

      End Function

      Private Sub Command1_Click()

      Dim M As String, K As String, C As String, flag As Boolean

      Dim i As Integer, t As Integer, ch As Integer, pos As Integer, j As Integer

      M = Text1.Text             ′明文

      K = Text2.Text              ′密钥

      t = Len(K)

      K = X2D(K)                   ′将密钥全部转成大写

      C = “ ”                      ′加密后的结果

      For i = 1 To Len(M)

      ch = Asc(Mid(M, i, 1))

      flag = False

      If ch >= 97 And ch <= 122 Then ch = ch - 32: flag = True

        pos =                ′密钥的字符位置值

      If pos = 0 Then pos = t

            j = Asc(Mid(K, pos, 1))               ′密钥字符的ASCII值

           ch = ch - MIN_ASC

           j = j - MIN_ASC

            ch =

            ch = ch + MIN_ASC

        If flag Then ch = ch + 32         ′设置字母的大小写形式

           C = C & Chr(ch)

      Next i

      Text3.Text = C

      End Sub

微信扫码预览、分享更方便