|
-
Feb 7th, 2012, 08:45 AM
#1
Thread Starter
New Member
What's wrong
i have this code to make a simple encryption in vb.2008
it should take a letter and change it/swap it for another for example "A"="B"
and so on and so forth,
i have a basic understanding of vb but not much and i have a vague idea of what i need to do but the code just doesnt seem to work and everything i try just doesnt work, i have used the "Replace" and "insert" methods
but they are not what i am looking for
Dim X(3) As Char
For i = 0 To 3
X(i) = ChrW(100)
Next i
Console.WriteLine(X[0]&X[1]&X[2]&X[3])
End Function
End Class
The X would be 25 because of the alphabet 
Hope you can help
Rich.vb
Last edited by richardMorris.vb; Feb 7th, 2012 at 09:30 AM.
-
Feb 7th, 2012, 09:22 AM
#2
Re: What's wrong
You'll have to post your code in order for us to help you.
-
Feb 7th, 2012, 09:26 AM
#3
Thread Starter
New Member
Re: What's wrong
sorry it's very basic but it gives you an idea of what i need:
Dim X(3) As Char
For i = 0 To 3
X(i) = ChrW(100)
Next i
Console.WriteLine(X[0]&X[1]&X[2]&X[3])
End Function
End Class
The X would be 25 because of the alphabet
cheers
Rich.vb
-
Feb 7th, 2012, 10:04 AM
#4
Re: What's wrong
duplicate posting - http://www.vbforums.com/showthread.php?t=671790
Please do not create more than one post for the same problem... it just leads to all kinds of confusion... people who reply to that post won't see this one, and people replying to this one won't see the other...
----
That said... your code at the moment does nothing but dispaly a string of 4 char 100 ... your'e not inserting or replacing anything...
-tg
-
Feb 7th, 2012, 10:30 AM
#5
Thread Starter
New Member
Re: What's wrong
could you help me with anything?
-
Feb 7th, 2012, 11:40 AM
#6
Re: What's wrong
As TG states, you aren't really doing anything in that code. All the loop does is puts four copies of ChrW(100) into the four array slots. That makes it pretty difficult to suggest anything. If you wanted to encrypt some string, you'd first need the string you wanted to encrypt, then you'd have some function to change the values into something else. There isn't a string in that code, nor is there a mechanism to supply one, nor is there even a need for one. Therefore, there really isn't much that can be said about it. I would expect that there be a string, then you would loop through the characters in the string either replacing each character with a different one, or getting the ASCII value for the character and adding a number to it, or something like that.
My usual boring signature: Nothing
 
-
Feb 7th, 2012, 11:51 AM
#7
Hyperactive Member
Re: What's wrong
Since there's not much to go on here(code didn't make much sense), maybe I can take a swing and hopefully not miss...
Perhaps, are you converting your characters to another by using .Replace()?
If you are then it could get a little tricky. Take this example..
String = 'abcde'
and your conversions are a=b, b=c, c=d, d=e, e=f
The problem that will occur is if you do...
String.Replace("a", "b"), results in String = 'bbcde'
Next... this is where the problem occurs.
String.Replace("b", "c"), results in String = 'cccde'
With this example you will eventually end up with 'fffff', but that's only because I have consecutive alpha values, maybe in your case you don't but this will still occur. Which would make it impossible to bring it back to what it was by reversing the order.
To do this your going to have to go through your string, character by character and build it into another string.
vbnet Code:
Dim String1 As String = "abcde" Dim String2 As String = "" Dim sub As String For i as Int32 = 0 to String1.Length-1 sub = String1.SubString(i, 1) Select Case sub 'This can implement your own way of determining your values. This was for the sake of my example. Case "a": String2 &= "b" Case "b": String2 &= "c" Case "c": String2 &= "d" Case "d": String2 &= "e" Case "e": String2 &= "f" End Select Next i 'This should result in String1 = "bcdef"
I mean there are a hundred ways you could be doing this, and I'm sure there's a simpler way. But for the sake of learning I keep it simple, in hopes you will understand and build from there. 
Hope this was your problem, and can help you solve it!
Last edited by DavesChillaxin; Feb 7th, 2012 at 11:54 AM.
-
Feb 7th, 2012, 12:30 PM
#8
Thread Starter
New Member
Re: What's wrong
Thank you very much for help
unfortunately it didn't work and i dont understand why haha
yer basically what i am aiming for is a ceasar cipher if that helps anyone?
once again thank you, your time was very much given to a grateful person
Thanks
R.Vb
A programmer in need, is a programmer in deed
-
Feb 7th, 2012, 12:40 PM
#9
Re: What's wrong
Aah... ok... that makes it a little easier then.... The Caesar Cipher is a shift cipher... first thing to do is determine what shift you want... and if you want to be able to change it or leave it alone.
then the steps to encrypt it are as follows:
1) loop through each letter
2) get the value (ASCII)
3) Apply the shift value
4) convert it back to a char (ToChar)
5) add the character to a new string (not the original one)
6) Repeat the loop until done.
then to decrypt it you apply the same logic but reverse the shift value.
-tg
-
Feb 7th, 2012, 01:00 PM
#10
Thread Starter
New Member
Re: What's wrong
thank you tg,
my issue is that for example i make a = £
just so i text code is unreadable.....
would you be able to shed any light on this situation
many thanks
R.Vb
A programmer in need, is a programmer in deed
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|