Click here to Skip to main content
11,802,762 members (71,772 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB 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)
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
Edited 19-Apr-13 9:03am
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
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.
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. :-)
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.

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

  Print Answers RSS
0 KrunalRohit 366
1 OriginalGriff 365
2 F-ES Sitecore 295
3 CPallini 270
4 Sergey Alexandrovich Kryukov 239
0 OriginalGriff 2,950
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,695
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 19 Apr 2013
Copyright © CodeProject, 1999-2015
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