TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to VBNET

VB.NET ROT13 Encode Function

Implement the ROT13 transformation cipher using the Asc and Chr Functions.
ROT13. The ROT13 algorithm encodes plain text in VB.NET. What is the concept of ROT13? In this algorithm, the letters A-Z and a-z are rotated 13 places. This scrambles the text but is easily reversible.Strings
Example. To begin, the Main function calls the Rot13 function. We test to make sure the Rot13 function, when called twice, correctly reverses the operation. In the Rot13 function, we receive one String parameter and return a new String value.Function

Asc: We first use the Asc function to convert several important characters to integers. These could be hard-coded in the program.

Val, Asc

ToCharArray: We invoke ToCharArray and loop over all the chars in the string. We use Asc on each char to convert it to its ASCII representation.

ToCharArrayChar Array

And: The shifting logic then tests letters and changes their values to be 13 greater or 13 less.

Finally: The String constructor converts the character array back to a string and returns it.

String Constructor
VB.NET program that implements ROT13 algorithm Module Module1 Sub Main() ' Use Rot13. Console.WriteLine("dotnetCodex.com ZAza") Console.WriteLine(Rot13("dotnetCodex.com ZAza")) Console.WriteLine(Rot13(Rot13("dotnetCodex.com ZAza"))) End Sub Public Function Rot13(ByVal value As String) As String ' Could be stored as integers directly. Dim lowerA As Integer = Asc("a"c) Dim lowerZ As Integer = Asc("z"c) Dim lowerM As Integer = Asc("m"c) Dim upperA As Integer = Asc("A"c) Dim upperZ As Integer = Asc("Z"c) Dim upperM As Integer = Asc("M"c) ' Convert to character array. Dim array As Char() = value.ToCharArray ' Loop over string. Dim i As Integer For i = 0 To array.Length - 1 ' Convert to integer. Dim number As Integer = Asc(array(i)) ' Shift letters. If ((number >= lowerA) AndAlso (number <= lowerZ)) Then If (number > lowerM) Then number -= 13 Else number += 13 End If ElseIf ((number >= upperA) AndAlso (number <= upperZ)) Then If (number > upperM) Then number -= 13 Else number += 13 End If End If ' Convert to character. array(i) = Chr(number) Next i ' Return string. Return New String(array) End Function End Module Output dotnetCodex.com ZAza qbgargcreyf.pbz MNmn dotnetCodex.com ZAza
Summary. The ROT13 algorithm is not a world-leading encryption technology. It is easily broken and won't stop others from reading your important secrets. But for those of us who have few important secrets, it can help disguise data.
Security by obscurity is useful if you don't care about the security of your data. ROT13 is helpful for learning how to write string-manipulation code. Beyond that, it is limited.
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf