May 15, 2015 04:01 AM (This post was last modified: Apr 3, 2016 05:08 AM by Neos07.)
ROT13 Encryption
ROT13 replaces each letter by its partner 13 characters further along the alphabet. For example, HELLO becomes URYYB (or, reversing, URYYB becomes HELLO again).
Source Code:
Quote:Public Class Form1
Dim Letter() As String = {"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", "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"}
Dim Letter2() As String = {"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", "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"}
Dim str As String
Private Sub EncryptButton_Click(sender As Object, e As EventArgs) Handles EncryptButton.Click
str = TextToEncryptTextBox.Text
TextToEncryptTextBox.Clear()
For i As Integer = 0 To str.Length - 1
For j As Integer = 0 To 51
If str(i) = Letter(j) Then
TextToEncryptTextBox.Text = TextToEncryptTextBox.Text + Letter2(j)
GoTo Line1
End If
Next
TextToEncryptTextBox.Text = TextToEncryptTextBox.Text + str(i)
Line1:
Next
End Sub
End Class
That's basically a Caesar Shift with a shiftkey of 13.
A little hint:
If you want to improve it you can directly use the ascii-table to
figure out the next chars and not rely on a list of chars. :)
May 15, 2015 11:53 AM (This post was last modified: May 15, 2015 11:59 AM by Neos07.)
Thank you guys for everything!
(May 15, 2015 05:39 AM)Hiiro Wrote: You could do something like this too:
PHP Code
<?php Private Shared Sub Main(args As String()) Console.WriteLine(ROT("Hello", 13)) Console.ReadLine() End Sub
Public Shared Function ROT(input As String, rotation As Integer) As String Dim output As New StringBuilder()
For Each chr As Char In input If Char.IsLetter(chr) Then Dim upper As Boolean = Char.IsUpper(chr)
Dim rot__1 As Integer = Char.ToLower(chr) + rotation Dim min As Integer = 97, max As Integer = 122
While rot__1 < min rot__1 += 26 End While While rot__1 > max rot__1 -= 26 End While
output.Append(If(upper, Char.ToUpper(CChar(rot__1)), CChar(rot__1))) Else output.Append(chr) End If Next
Return output.ToString() End Function
I used a code converter
That's a good code thx, it's for generally ROT not just ROT13! ✌
(May 15, 2015 05:41 AM)GhostCode Wrote: That's basically a Caesar Shift with a shiftkey of 13.
A little hint:
If you want to improve it you can directly use the ascii-table to
figure out the next chars and not rely on a list of chars. :)
Thanks, i will go search about ascii-table! :)
(May 15, 2015 11:32 AM)$lick Wrote: This is encoding not encryption...
Can you please explain what is the difference between them?
(May 15, 2015 11:53 AM)Neos07 Wrote: Thank you guys for everything!
That's a good code thx, it's for generally ROT not just ROT13! ✌
Thanks, i will go search about ascii-table! :)
Can you please explain what is the difference between them?
(Apr 3, 2016 05:02 AM)BahNahNah Wrote: What? 😶
You need two functions.
ROT13 is an exception because it only needs one function of encoding/decoding and that because the number of letters is 26 so when yrou rotate the letter "A" it will become "N" and if you rotate "N" it will rebecome back to "A" (that's only in case of ROT13).
(Apr 3, 2016 05:06 AM)Neos07 Wrote: ROT13 is an exception because it only needs one function of encoding/decoding and that because the number of letters is 26 so when yrou rotate the letter "A" it will become "N" and if you rotate "N" it will rebecome back to "A" (that's only in case of ROT13).
So it cant keep the character case or support numbers? 😑
Heres my spin: Spoiler (Click to View)
(Map must be a even length)
Lotta blood to let, peace to make, give a fuk about a check