Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi.. I have a question.. My teacher gave me an assignment to encrypt files using RSA.. I understand the system very well.. I converted the file to byte[].. And when I do the encryption, I get values larger than the values permitted for the type byte and the program stops.. Is there any way to avoid that?
 
Sub encrypt()
    For i = 0 To bytes.Length - 1
        bytes(i) = fast(bytes(i), ee)
    Next
End Sub
 

 
    Function fast(ByVal aa As Object, ByVal zz As Integer) As Integer
        Dim xx As Integer
        xx = 1
        While zz <> 0
            While zz Mod 2 = 0
                zz = zz \ 2
                aa = (aa * aa) Mod n
            End While
            zz = zz - 1
            xx = (xx * aa) Mod n
        End While
        Return xx
    End Function
 
It stops after the fast function ends.. Means after it returns the resulted value...
Posted 19-Apr-13 9:07am
Edited 19-Apr-13 10:03am
v2
Comments
Nelek at 19-Apr-13 14:11pm
   
Maybe a bit more information...
ryanb31 at 19-Apr-13 14:20pm
   
Need more info. What are you trying to encrypt that is so big it won't fit into byte[]?
OriginalGriff at 19-Apr-13 14:37pm
   
How are you doing the encrypt? show the relevant code fragment.
(Use the "Improve question" widget to edit your question and provide better information.)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can't possibly get values larger than byte if you were doing the encryption properly. Now, if you created an array of bytes to hold the resulting encrypted data, THEN you might get some kind of array overflow.
 
Without seeing your code, it's impossible to tell you what you did wrong.
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 20-Apr-13 0:05am
   
I voted 4 (I mean, not 5) by the following reason: in an array of byte, it is impossible to values larger than byte even of encryption is done improperly or even completely failed. :-)
—SA
Dave Kreskowiak at 20-Apr-13 8:20am
   
Yeah, look at his code. He's getting the "overflow" (not even the real error) because his array is Byte, but his "fast" function is returning Integer. He's trying to stuff an Intger into a Byte.
Sergey Alexandrovich Kryukov at 20-Apr-13 20:29pm
   
I see, thank you for the explanation of what could be perceived as "overflow"; this is just the usual wrapping of the value of the maximum. I only say that this "overflow" has nothing to do with the validity of encryption.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,192
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 19 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100