Click here to Skip to main content
13,088,101 members (69,974 online)
Rate this:
Please Sign up or sign in to vote.
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?

Sub encrypt()
    For i = 0 To bytes.Length - 1
        bytes(i) = fast(bytes(i), ee)
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 8:07am
Updated 19-Apr-13 9:03am
Nelek 19-Apr-13 14:11pm
Maybe a bit more information...
ryanb31 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.)
Rate this: bad
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.
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. :-)
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 19 Apr 2013
Copyright © CodeProject, 1999-2017
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