473,403 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

crptyohraphy question

I have this source code,

Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2. Imports System.Text
  3. Imports System.Security.Cryptography
  4.  
  5. Module Module1
  6.  
  7.     Sub Main()
  8.  
  9.  
  10.     End Sub
  11.     Public TheKey(7) As Byte
  12.  
  13.  
  14.     Private Vector() As Byte = {&H12, &H44, &H16, &HEE, &H88, &H15, &HDD, &H41}
  15.  
  16.  
  17.  
  18.     Sub Encrypt(ByVal inName As String, ByVal outName As String)
  19.         Try
  20.             Dim storage(4096) As Byte   'create buffer 
  21.             Dim totalBytesWritten As Long = 8  'Keeps track of bytes written. 
  22.  
  23.             Dim packageSize As Integer   'Specifies the number of bytes written at one time. 
  24.  
  25.             'Declare the file streams. 
  26.             Dim fin As New FileStream(inName, FileMode.Open, FileAccess.Read)
  27.             Dim fout As New FileStream(outName, FileMode.OpenOrCreate, _
  28.               FileAccess.Write)
  29.             fout.SetLength(0)
  30.  
  31.             Dim totalFileLength As Long = fin.Length  'Specifies the size of the source file. 
  32.  
  33.             'create the Crypto object 
  34.             Dim des As New DESCryptoServiceProvider()
  35.  
  36.             Dim crStream As New CryptoStream(fout, _
  37.                    des.CreateEncryptor(TheKey, Vector), CryptoStreamMode.Write)
  38.  
  39.             'flow the streams 
  40.                 While  totalBytesWritten < totalFileLength 
  41.                 packageSize = fin.Read(storage, 0, 4096)
  42.                 crStream.Write(storage, 0, packageSize)
  43.                 totalBytesWritten = Convert.ToInt32(totalBytesWritten + packageSize / des.BlockSize * des.BlockSize)
  44.             End While
  45.  
  46.             crStream.Close()
  47.  
  48.  
  49.         Catch e As Exception
  50.             MsgBox(e.Message)
  51.         End Try
  52.  
  53.     End Sub
  54.  
  55.     Sub Decrypt(ByVal inName As String, ByVal outName As String)
  56.  
  57.         Try
  58.  
  59.             Dim storage(4096) As Byte
  60.             Dim totalBytesWritten As Long = 8
  61.             Dim packageSize As Integer
  62.             Dim fin As New FileStream(inName, FileMode.Open, FileAccess.Read)
  63.             Dim fout As New FileStream(outName, FileMode.OpenOrCreate, _
  64.               FileAccess.Write)
  65.             fout.SetLength(0)
  66.             Dim totalFileLength As Long = fin.Length
  67.  
  68.  
  69.             Dim des As New DESCryptoServiceProvider()
  70.             Dim crStream As New CryptoStream(fout, _
  71.               des.CreateDecryptor(TheKey, Vector), CryptoStreamMode.Write)
  72.  
  73.             Dim ex As Exception
  74.  
  75.                 While  totalBytesWritten < totalFileLength 
  76.                 packageSize = fin.Read(storage, 0, 4096)
  77.                 crStream.Write(storage, 0, packageSize)
  78.                 totalBytesWritten = Convert.ToInt32(totalBytesWritten + packageSize / des.BlockSize * des.BlockSize)
  79.                 Console.WriteLine("Processed {0} bytes, {1} bytes total", packageSize, _
  80.                    totalBytesWritten)
  81.             End While
  82.  
  83.             crStream.Close()
  84.  
  85.         Catch e As Exception
  86.             MsgBox(e.Message & "Please ensure that you are using the correct password")
  87.         End Try
  88.  
  89.     End Sub
  90.  
  91.     Sub CreateKey(ByVal strKey As String)
  92.  
  93.         ' Byte array to hold key 
  94.         Dim arrByte(7) As Byte
  95.  
  96.         Dim AscEncod As New ASCIIEncoding()
  97.         Dim i As Integer = 0
  98.         AscEncod.GetBytes(strKey, i, strKey.Length, arrByte, i)
  99.  
  100.         'Get the hash value of the password 
  101.         Dim hashSha As New SHA1CryptoServiceProvider()
  102.         Dim arrHash() As Byte = hashSha.ComputeHash(arrByte)
  103.  
  104.         'put the hash value into the key 
  105.         For i = 0 To 7
  106.             TheKey(i) = arrHash(i)
  107.         Next i
  108.  
  109.     End Sub
  110.  
  111. End Module

and i am getting this error

Name 'lt' is not declared.
and
Character is vaild

and ideas??
Nov 20 '09 #1
2 1440
tlhintoq
3,525 Expert 2GB
Visual Studio would have stopped on the line where it has this problem, or the error pallet will tell you the file name and line number where the problem is.

On that line, you have a variable "It" that you are trying to use, only you have declared it before trying to use it.
It looks to be in your 'Flow the streams portion &lt
Nov 20 '09 #2
!NoItAll
297 100+
Try
Expand|Select|Wrap|Line Numbers
  1.  While  totalBytesWritten < totalFileLength 
This is what happens when you just cut and paste code from a web page. The "<" (less than) symbol gets turned into an HTML entity "&lt;"
There are two instances of this error that I can see....
Nov 29 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Mohammed Mazid | last post by:
Can anyone please help me on how to move to the next and previous question? Here is a snippet of my code: Private Sub cmdNext_Click() End Sub Private Sub cmdPrevious_Click() showrecord
3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
10
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
10
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server...
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
56
by: spibou | last post by:
In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ?
2
by: Allan Ebdrup | last post by:
Hi, I'm trying to render a Matrix question in my ASP.Net 2.0 page, A matrix question is a question where you have several options that can all be rated according to several possible ratings (from...
3
by: Zhang Weiwu | last post by:
Hello! I wrote this: ..required-question p:after { content: "*"; } Corresponding HTML: <div class="required-question"><p>Question Text</p><input /></div> <div...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.