Andrio_Celos

A binary-coded ASCII encoder/decoder

Aug 10th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.28 KB | None | 0 0
  1.     Sub Encode()
  2.         Dim Text As String = "Hello, world!"
  3.         Dim Code As String = ""
  4.         For Each c In Text
  5.             Dim b = AscW(c)
  6.             b = b And 255
  7.             Code &= If(b And 128, "1", "0") & If(b And 64, "1", "0") & If(b And 32, "1", "0") & If(b And 16, "1", "0") &
  8.              If(b And 8, "1", "0") & If(b And 4, "1", "0") & If(b And 2, "1", "0") & If(b And 1, "1", "0") & " "
  9.         Next
  10.         Console.WriteLine(Code)
  11.         Console.ReadKey(True)
  12.     End Sub
  13.  
  14.     Sub Decode()
  15.         Dim Code As String = "01001000 01100101 01101100 01101100 01101111 00101100 00100000 01110111 01101111 01110010 01101100 01100100 00100001"
  16.         Dim Text As String = ""
  17.         Dim i As Integer
  18.         For i = 0 To Code.Length - 8 Step 9
  19.             Text &= ChrW(Byte.Parse(Code(i + 0)) << 7 Or
  20.                       Byte.Parse(Code(i + 1)) << 6 Or
  21.                       Byte.Parse(Code(i + 2)) << 5 Or
  22.                       Byte.Parse(Code(i + 3)) << 4 Or
  23.                       Byte.Parse(Code(i + 4)) << 3 Or
  24.                       Byte.Parse(Code(i + 5)) << 2 Or
  25.                       Byte.Parse(Code(i + 6)) << 1 Or
  26.                       Byte.Parse(Code(i + 7)) << 0)
  27.         Next
  28.         Console.WriteLine(Text)
  29.         Console.ReadKey(True)
  30.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment