You said "easy", correct?:D
'// encrypt. Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click With TextBox1 .Text = .Text.Replace("a", "z").Replace("b", "y").Replace("c", "x") End With End Sub '// decrypt. Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click With TextBox1 .Text = .Text.Replace("z", "a").Replace("y", "b").Replace("x", "c") End With End Sub
That is actually really helpful :)
Sorry to jump in on someone else's thread but could you show me a way of encryption which is still easy (ish!) to write but a bit more secure. So maybe a level or two up from this encryption?
This would be amazing if you could. Many thanks!
See if this helps.
Public Class Form1 Private arLetterChars() As Char = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 " Private arEncryptedChars() As Char = "¿s¢çc‹i˜Ö´åÄÚKÍìæ¯~4Ûÿ5ÑûÏÉí³èô§ŠÀÙ9ÒÓ?þ.äƒ%*š¾†±HI2@Ã¦Œ," '// encrypt. Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click With TextBox1 For Each myTextBoxChar As Char In .Text '// loop thru TextBox, one char. at a time. For i As Integer = 0 To arLetterChars.Length - 1 '// loop thru all letters in the Array. '// if TextBox char ='s the char in your Array, replace the TextBox char with the same #'ed Array char of the Encrypted letters. If myTextBoxChar = arLetterChars(i) Then .Text = .Text.Replace(myTextBoxChar, arEncryptedChars(i)) Next Next End With End Sub '// decrypt. Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click With TextBox1 For Each myTextBoxChar As Char In .Text '// loop thru TextBox, one char. at a time. For i As Integer = 0 To arEncryptedChars.Length - 1 '// loop thru all Encrypted char.s in the Array. '// if TextBox char ='s the char in your Array, replace the TextBox char with the same #'ed Array char of the Letters. If myTextBoxChar = arEncryptedChars(i) Then .Text = .Text.Replace(myTextBoxChar, arLetterChars(i)) Next Next End With End Sub End Class
This uses 2 For/Next loops.
First loop, loops through each char. in the TextBox, one at a time. The loop inside the first loop, loops through the char.s in your Arrays, depending on which Array to use, if to encrypt or decrypt.
If a letter is the same letter as in your selected Array, it replaces the same Indexed char. from one Array, with a char. from the other Array.
The weird looking char.s were found by loading a small image in Notepad.
Many thanks, this is perfect. :)
One last thing, I hope I'm not being a pain, but do you know of a way to make each character different, but the computer knows how to distinguish which letters are what and so on. For example, the password hello, could this be encrypted so that the l's have a different character and hence it makes it harder to crack.
If not, no worries you've been a massive help, thank you.
From "Sybex - Mastering Microsoft Visual Basic 2008":
Another benefit of using streams is that you can combine them. The typical example is that of encrypting and decrypting data. Data is encrypted through a special type of Stream, the CryptoStream. You write plain data to the CryptoStream, and they’re encrypted by the stream itself. In other words, the CryptoStream object accepts plain data and emits encrypted data. You can connect the CryptoStream object to another Stream object that represents a file andwrite the encrypted data directly to the file. Your code uses simple statements to write data to the CryptoStream object,
which encrypts the data and then passes it to another stream that writes the encrypted data to a file.
I haven't tried this but it may point you in the right direction of a more secure encryption.
Sir Codeorder. Thank you for the very helpful code. Your one of kind. Thank you again and Good day! Also to Sir Reverend Jim. Thank you for the suggestions. i'll to research also for that. :)
I know this is marked as solved but I wanted to add a link to a walkthrough from Microsoft.
Walkthrough: Encrypting and Decrypting Strings in Visual Basic
Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...
Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.
This is the result of previous question answered :
code for the listbox - datagridview interaction
At the top of the code ...
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...