Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
2.60/5 (3 votes)
See more:
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?

VB
Sub encrypt()
    For i = 0 To bytes.Length - 1
        bytes(i) = fast(bytes(i), ee)
    Next
End Sub




VB
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
Updated 19-Apr-13 9:03am
v2
Comments
Nelek 19-Apr-13 14:11pm    
Maybe a bit more information...
ZurdoDev 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 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.)

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.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 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 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 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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900