Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


Word Encoder/Decoder | Made using string and stringbuilder class filter_list
Author
Message
Word Encoder/Decoder | Made using string and stringbuilder class #1
So my professor gave the assignment of making a word encoder/decoder using just the string and stringbuilder classes. I have no use for this project though besides getting a good grade in class so I've decided to share it here. I know it's very easy to crack but it's hard to make something very secure using just the string and stringbuilder class. Also here's an image for it:
[Image: iE5shEQeczDCj.gif]

Source: http://www.mediafire.com/?bgfsotsdow5u006

So what do you guys think about it?
#steez

Reply

RE: Word Encoder/Decoder | Made using string and stringbuilder class #2
Very, very nice! I like it.

How long did you need for it?
I'm back.

Reply

RE: Word Encoder/Decoder | Made using string and stringbuilder class #3
(05-20-2012, 01:17 AM)Don. Wrote: Very, very nice! I like it.

How long did you need for it?

10 mins coding and 5 mins commenting out everything. Wasn't very challenging lol
#steez

Reply

RE: Word Encoder/Decoder | Made using string and stringbuilder class #4
Using methods that are already part of the .NET library is not good. There is actually already a method named Replace(), which you've overwritten here, and looping through the char values with "chr" there's also the Chr() function. Things like this are bad habit.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: Word Encoder/Decoder | Made using string and stringbuilder class #5
Try this:
Code:
Private Const alpha = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890`~!@#$%^&*()-_=+{}|[]\:"";'<>?,./ "

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Encrypt_Decrypt(TextBox1.Text)
End Sub

Private Sub Encrypt_Decrypt(FullText As String)
    Dim sb As New StringBuilder
    Array.ForEach(FullText.ToCharArray, Sub(c) sb.Append(If(alpha.Contains(c), alpha.Reverse()(alpha.IndexOf(c)), c)))
    TextBox1.Text = sb.ToString
    sb.Clear()
End Sub

[Image: pRZHP.gif]
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: Word Encoder/Decoder | Made using string and stringbuilder class #6
(05-20-2012, 03:46 PM)PhazeShift Wrote: Using methods that are already part of the .NET library is not good. There is actually already a method named Replace(), which you've overwritten here, and looping through the char values with "chr" there's also the Chr() function. Things like this are bad habit.

I've never heard of the Chr() function before, thanks for letting me know about it. And when you say there's already a method named Replace, I didn't really overwrite that as I'm still using .replace inside the sub. I just made a sub for that to shorten my code and called it that.

(05-20-2012, 04:50 PM)PhazeShift Wrote: Try this:
Code:
Private Const alpha = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890`~!@#$%^&*()-_=+{}|[]\:"";'<>?,./ "

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Encrypt_Decrypt(TextBox1.Text)
End Sub

Private Sub Encrypt_Decrypt(FullText As String)
    Dim sb As New StringBuilder
    Array.ForEach(FullText.ToCharArray, Sub(c) sb.Append(If(alpha.Contains(c), alpha.Reverse()(alpha.IndexOf(c)), c)))
    TextBox1.Text = sb.ToString
    sb.Clear()
End Sub

[Image: pRZHP.gif]

Yet again, you've found a easier and shorter way to create what I've done. Thanks for the tips and maybe one day I'll be simplifying your code for you Smile
#steez

Reply

RE: Word Encoder/Decoder | Made using string and stringbuilder class #7
Cool work done, keep up man!

1010011001111010010010101
0110G10H10O101S010T10101
1010100010100100101001001


Reply

RE: Word Encoder/Decoder | Made using string and stringbuilder class #8
Quote:I've never heard of the Chr() function before, thanks for letting me know about it.

Still, best advice I have here for you is to keep things unique. If you create methods or variables which can be overriden easily (especially enums), that pre-existing one default with the .NET libraries is now invisible when you want to use it.

Here's the Chr() Function for you: http://msdn.microsoft.com/en-us/library/...s.71).aspx

There's both Chr() and ChrW().

Quote:And when you say there's already a method named Replace, I didn't really overwrite that as I'm still using .replace inside the sub. I just made a sub for that to shorten my code and called it that.

Oh... no Smile You've actually overriden Replace(), not String.Replace() as the extension method.

This one:
Code:
Dim t As String = "test 123"
t = Replace(t, "test", "testing")

Look:
Code:
// Code size       48 (0x30)
  .maxstack  6
  .locals init ([0] string str1,
           [1] string str2)
  IL_0000:  nop
  IL_0001:  ldstr      "test2"
  IL_0006:  ldstr      "test"
  IL_000b:  ldstr      "testing"
  IL_0010:  ldc.i4.1
  IL_0011:  ldc.i4.m1
  IL_0012:  ldc.i4.0
  IL_0013:  call       string [Microsoft.VisualBasic]Microsoft.VisualBasic.Strings::Replace(string,
                                                                                            string,
                                                                                            string,
                                                                                            int32,
                                                                                            int32,
                                                                                            valuetype [Microsoft.VisualBasic]Microsoft.VisualBasic.CompareMethod)
  IL_0018:  stloc.0
  IL_0019:  ldstr      "test1"
  IL_001e:  ldstr      "test"
  IL_0023:  ldstr      "testing"
  IL_0028:  callvirt   instance string [mscorlib]System.String::Replace(string,
                                                                        string)
  IL_002d:  stloc.1
  IL_002e:  nop
  IL_002f:  ret

There's one from the VisualBasic methods, and the System.String namespace for VB in terms of Replace functions. I think you're also just unaware that the VisualBasic Replace() function existed Smile

My homework for you:
-Research Chr()
-Research Replace()

Here's the Replace functions, both the one you are thinking i'm talking about, and the one I am talking about:
http://msdn.microsoft.com/en-us/library/...s.80).aspx
http://msdn.microsoft.com/en-us/library/...place.aspx

Quote:Yet again, you've found a easier and shorter way to create what I've done. Thanks for the tips and maybe one day I'll be simplifying your code for you

Just keep at it, i've been using .NET for quite a while now. And I practically use it everyday still.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: Word Encoder/Decoder | Made using string and stringbuilder class #9
Yea I read up on the chr() function right after you mentioned it, and thanks for clearing that up. I'll keep this in mind for future projects.
#steez

Reply







Users browsing this thread: 2 Guest(s)