Solved

Basic Encryption

Posted on 2006-10-19
12
244 Views
Last Modified: 2012-08-14
Hi

how do i convert

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

to

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

basically just going back 3 characters

so if i type "narmi" in the textbox and click a button i should get "kxojg"

i think!! :)

thanks

narmi2
0
Comment
Question by:narmi2
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 10

Expert Comment

by:gangwisch
ID: 17767218
dim txt as string="abcd"

for i as integer=0 to origtxt.length-1
txt.chars(i)= asc(txt.chars(i))-3
'you will need to check if >80
next
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17767258
Another way:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim index As Integer
        Dim vals() As Char = "abcdefghijklmnopqrstuvwxyz".ToCharArray
        Dim input As New System.Text.StringBuilder(TextBox1.Text)
        For i As Integer = 0 To input.Length - 1
            index = Array.IndexOf(vals, input.Chars(i))
            If index <> -1 Then
                index = index - 3
                If index < 0 Then
                    index = vals.Length + index
                End If
                input.Chars(i) = vals(index)
            End If
        Next
        TextBox1.Text = input.ToString
    End Sub

This leaves any characters that are not "a-z" intact.
0
 
LVL 1

Author Comment

by:narmi2
ID: 17767404
Idle Mind how would i reverse that?  so it does the opposite?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17767433
Define opposite?

You mean so that "abc" becomes "def"?
0
 
LVL 1

Author Comment

by:narmi2
ID: 17767444
gangwisch - i get an error with your code saying "property char is read only"
0
 
LVL 1

Author Comment

by:narmi2
ID: 17767458
idel mind,

i mean if i start off with "narmi" and click encrypt button, i get "kyojf"

then i want to click decrypt when "kyojf" is in the box which should give me "narmi" back again.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 17767486
ah...duh...lol!

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim index As Integer
        Dim vals() As Char = "abcdefghijklmnopqrstuvwxyz".ToCharArray
        Dim input As New System.Text.StringBuilder(TextBox1.Text)
        For i As Integer = 0 To input.Length - 1
            index = Array.IndexOf(vals, input.Chars(i))
            If index <> -1 Then
                index = index - 3
                If index < 0 Then
                    index = vals.Length + index
                End If
                input.Chars(i) = vals(index)
            End If
        Next
        TextBox1.Text = input.ToString
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim index As Integer
        Dim vals() As Char = "abcdefghijklmnopqrstuvwxyz".ToCharArray
        Dim input As New System.Text.StringBuilder(TextBox1.Text)
        For i As Integer = 0 To input.Length - 1
            index = Array.IndexOf(vals, input.Chars(i))
            If index <> -1 Then
                index = index + 3
                If index > vals.GetUpperBound(0) Then
                    index = index - vals.Length
                End If
                input.Chars(i) = vals(index)
            End If
        Next
        TextBox1.Text = input.ToString
    End Sub
0
 
LVL 1

Author Comment

by:narmi2
ID: 17767511
perfec :)
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17767530
Written slightly more intelligently...

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = Convert(TextBox1.Text, True)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = Convert(TextBox1.Text, False)
    End Sub

    Public Function Convert(ByVal str As String, ByVal Encrypt As Boolean) As String
        Dim index As Integer
        Dim vals() As Char = "abcdefghijklmnopqrstuvwxyz".ToCharArray
        Dim input As New System.Text.StringBuilder(str)
        For i As Integer = 0 To input.Length - 1
            index = Array.IndexOf(vals, input.Chars(i))
            If index <> -1 Then
                If Encrypt Then
                    index = index - 3
                    If index < 0 Then
                        index = vals.Length + index
                    End If
                Else
                    index = index + 3
                    If index > vals.GetUpperBound(0) Then
                        index = index - vals.Length
                    End If
                End If
                input.Chars(i) = vals(index)
            End If
        Next
        Return input.ToString
    End Function
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17767560
If you want actual encryption (with a key that is) then see:
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_21821682.html
0
 
LVL 7

Expert Comment

by:Mohamed Zedan
ID: 17767599
It's like this but first "narmi" encrypted is "kxojf"

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim index As Integer
        Dim vals() As Char = "abcdefghijklmnopqrstuvwxyz".ToCharArray
        Dim input As New System.Text.StringBuilder(TextBox1.Text)
        For i As Integer = 0 To input.Length - 1
            index = Array.IndexOf(vals, input.Chars(i))
            If index <> -1 Then
                index = index + 3
                'If index < 0 Then
                '    index = vals.Length + index
                'End If
                if index > vals.length -1  then
                    index = index - vals.length
                end if
                input.Chars(i) = vals(index)
            End If
        Next
        TextBox1.Text = input.ToString
    End Sub

I deduced that it's only a matter of reversing the - to +
and checking for the opposite condition for index.
:)
0
 
LVL 7

Expert Comment

by:Mohamed Zedan
ID: 17767611
sorry i was too late :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Converting C# Objects into JSON file 7 64
Clone Visual studio 2013 solution 5 24
Change data in datatable 8 29
Visual Studio editor? 1 37
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now