Home Computer Tutorials Computer Knowledge Write a string encryption program in vb 2008 to encrypt the letters of an input line of characters

Write a string encryption program in vb 2008 to encrypt the letters of an input line of characters

Jan 15, 2024 pm 03:39 PM

Use vb 2008 to write a simple encryption program that will input all the letters in a line of string

Dim S1 As String

Dim S2 As String

S1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJ"

S2 = "abcdefghijklmnopqrstuvwxyzabcdefghij"

Dim LStr As String

LStr = "AXDCF1245CDxhsavs" # Keep the original text

Dim TStr As String

Dim i As Integer

Dim S As String

TStr = """

For i = 1 To Len(LStr)

S = Mid(LStr, i, 1)

If InStr(S1, S) 0 Then

S = Mid(S1, InStr(S1, S) 10, 1)

ElseIf InStr(S2, S) 0 Then

S = Mid(S2, InStr(S2, S) 10, 1)

End If

TStr = TStr & S

Next i

Print TStr

VB encryption algorithm

First the program defines two strings k1 and k2;

Here he provides a variable named Text1, which should be a global variable and has been defined before the program.

First, we need to define a string variable code to store the text in Text1. Then, use the LCase() function to convert the uppercase letters in Text1 to lowercase letters.

The encryption process begins, which is a cyclic process.

In this loop, set the range of i from 1 to the length of code

At the beginning of each loop, take out each letter in the code and assign it to the s variable.

Then determine if s is not an empty string, assign n as the "distance" between the letters in s and the letter a (it is assumed that you already understand this concept, if not, please think about it carefully) .

Assume that the position of the letter 'i' in the string s in the string code is the nth position. If n is not a multiple of 2, then we will add the nth letter to the string decode. This letter comes from String k1. If n is a multiple of 2, then we will add the nth letter from the string k2 to the string decode.

In the process of judging whether s is a null character just now, if the obtained s is indeed a null character, then we will jump to the following processing process.

Assuming that the entered letter is not a multiple of 2, then change the letter of space into the 27th letter of k1, which is p, and add it to the 27th letter of k2, which is z.

Finally assign decode to text2.

Actually, this procedure is very simple. First define two strings, each containing 27 letters, including 26 letters and a space. Then shuffle the order of one of the strings. Next, according to the string that needs to be encrypted, take out each letter one by one, and determine the mask letter corresponding to k1 or k2 according to the position of the letter in the string. In this way, encryption operations can be achieved.

The vb program needs to convert the input original string into an uppercase string, encrypt it and output it

Dim s As String

Private Sub Command1_Click()

's = InputBox ("Please enter an English string:")

s = "I have an English book. It has 1234 pages."

For i = 1 To Len(s)

C = UCase(Mid(s, i, 1))

If C >= "A" And C

C = Chr(Asc(C) - 3)

If C is less than "A", then C will be set to the corresponding character of the ASCII code plus 26.

End If

Mid(s, i, 1) = C

Next i

MsgBox ("The encrypted string is: " & vbCrLf & s)

End Sub

Private Sub Command2_Click()

For i = 1 To Len(s)

C = Mid(s, i, 1)

If C >= "A" And C

C = Chr(Asc(C) 3)

If C is greater than "Z", then C will be equal to Chr(Asc(C) - 26).

End If

Mid(s, i, 1) = C

Next i

MsgBox ("The decrypted string is: " & vbCrLf & s)

End Sub

Vb programming to write a small program that can encrypt and decrypt an input English string

The following is the VB program for encryption and decryption based on the last 2 digits of the student number:

Private Sub Form_Click()

x = Val(Right(Text1.Text, 2)) 'Get the last 2 digits of the student number

'The following is encryption

s = Text2.Text

s1 = s

For i = 1 To Len(s)

c = Mid(s1, i, 1)

Mid(s1, i, 1) = Chr(Asc(c) Xor x)

Next i

Text3.Text = s1

'The following is the decryption

s = s1

For i = 1 To Len(s)

c = Mid(s, i, 1)

Mid(s, i, 1) = Chr(Asc(c) Xor x)

Next i

Text4.Text = s

End Sub

用vb 2008编写一个简单加密程序将输入的一行字符串中的所有字母

The above is the detailed content of Write a string encryption program in vb 2008 to encrypt the letters of an input line of characters. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to Solve Windows Error Code "INVALID_DATA_ACCESS_TRAP" (0x00000004) How to Solve Windows Error Code "INVALID_DATA_ACCESS_TRAP" (0x00000004) Mar 11, 2025 am 11:26 AM

This article addresses the Windows "INVALID_DATA_ACCESS_TRAP" (0x00000004) error, a critical BSOD. It explores common causes like faulty drivers, hardware malfunctions (RAM, hard drive), software conflicts, overclocking, and malware. Trou

ENE SYS Maintenance: Tips and Tricks to Keep Your System Running Smoothly ENE SYS Maintenance: Tips and Tricks to Keep Your System Running Smoothly Mar 07, 2025 pm 03:09 PM

This article provides practical tips for maintaining ENE SYS systems. It addresses common issues like overheating and data corruption, offering preventative measures such as regular cleaning, backups, and software updates. A tailored maintenance s

5 Common Mistakes to Avoid During ENE SYS Implementation 5 Common Mistakes to Avoid During ENE SYS Implementation Mar 07, 2025 pm 03:11 PM

This article identifies five common pitfalls in ENE SYS implementation: insufficient planning, inadequate user training, improper data migration, neglecting security, and insufficient testing. These errors can lead to project delays, system failures

How do I edit the Registry? (Warning: Use with caution!) How do I edit the Registry? (Warning: Use with caution!) Mar 21, 2025 pm 07:46 PM

Article discusses editing Windows Registry, precautions, backup methods, and potential issues from incorrect edits. Main issue: risks of system instability and data loss from improper changes.

Discover How to Fix Drive Health Warning in Windows Settings Discover How to Fix Drive Health Warning in Windows Settings Mar 19, 2025 am 11:10 AM

What does the drive health warning in Windows Settings mean and what should you do when you receive the disk warning? Read this php.cn tutorial to get step-by-step instructions to cope with this situation.

How do I manage services in Windows? How do I manage services in Windows? Mar 21, 2025 pm 07:52 PM

Article discusses managing Windows services for system health, including starting, stopping, restarting services, and best practices for stability.

which application uses ene.sys which application uses ene.sys Mar 12, 2025 pm 01:25 PM

This article identifies ene.sys as a Realtek High Definition Audio driver component. It details its function in managing audio hardware, emphasizing its crucial role in audio functionality. The article also guides users on verifying its legitimacy

why won't driver asio.sys load why won't driver asio.sys load Mar 10, 2025 pm 07:58 PM

This article addresses the failure of the Windows asio.sys audio driver. Common causes include corrupted system files, hardware/driver incompatibility, software conflicts, registry issues, and malware. Troubleshooting involves SFC scans, driver upda

See all articles