So in my program, I need to do something that will try one thing, and if that fails, move on to another.
I've made a program that encrypts another program and then attaches a stub onto that encrypted program, so the stub of code can later decrypt and run the rest of the program.
The thing is, there are four possible encryption algorithms that can be applied to the program initially, so there are four possible decryption algorithms.
I need either a way to detect which algorithm it has been encrypted with, or a way to try all the other algorithms against it.
Is there something I could do that with? Like a try-catch with multiple catches?
2 Replies - 324 Views - Last Post: 16 June 2011 - 06:22 AM
#1
Is there any form of try-catch with multiple catches?
Posted 15 June 2011 - 08:23 PM
Replies To: Is there any form of try-catch with multiple catches?
#2
Re: Is there any form of try-catch with multiple catches?
Posted 15 June 2011 - 09:56 PM
Well, trys do support multiple catches, but not really in the way you want. It's more a way to handle different exceptions differently.
The way I'd do this is make a method for each one. The method should return null if it catches an exception. Then you can just stack if-else statements.
The way I'd do this is make a method for each one. The method should return null if it catches an exception. Then you can just stack if-else statements.
#3
Re: Is there any form of try-catch with multiple catches?
Posted 16 June 2011 - 06:22 AM
As Curtis mentioned try-catch handles multiple catch blocks.
But it sounds more like you need a switch...case construct.
I assume that since you wrote the encryption scheme you planned ahead enough to write *which* scheme you used in the file header - or did something similar. That there is some tell-tale indication of which scheme you used.
So read the header, determine the scheme, feed that to a switch...case block to do the decoding.
But it sounds more like you need a switch...case construct.
I assume that since you wrote the encryption scheme you planned ahead enough to write *which* scheme you used in the file header - or did something similar. That there is some tell-tale indication of which scheme you used.
So read the header, determine the scheme, feed that to a switch...case block to do the decoding.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|