I'm creating an encryption program, and the way it works is, every character is replaced with a specified number, then added to the full string. Then the option will be given to encrypt it with a password. The password is then also translated using a set of given numbers. The two strings will then be multiplied. As you can imagine, an entire message could very easily result in more than 64 bits of number. I need a way to get the answer and then put that number into a text file, preferably without having to do anything else manually. Any help would be greatly appreciated.
Asked
Active
Viewed 176 times
0
-
Use PowerShell rather than `cmd.exe`. – Bill_Stewart Jan 21 '16 at 23:08
-
For once, I agree with Bill. Math involving numbers larger than 2^32 (or non-integers) should be done by PowerShell. – SomethingDark Jan 21 '16 at 23:23
-
In pure batch scripting you have to work around the 32-bit limitation (see [this example](http://stackoverflow.com/a/33357948)); you can call PowerShell from a batch file however like in [this post](http://stackoverflow.com/a/13109266)... – aschipfl Jan 22 '16 at 02:38
-
I'm trying to get more than 64 bits of information, though. PowerShell still gives me the answer in scientific notation like VBScript and CMD. I'd like to think that there's a program out there that breaks the numbers down and multiplies each number individually like they teach you in school, but I'm beginning to think that just isn't even possible. – BatchAssassin Jan 23 '16 at 01:27
2 Answers
1
You can use this magical batch file at http://www.robvanderwoude.com/files/multiply_3rdparty_bat.txt.
The standard output of the file should be the answer to any multiplication problem, which you can retrieve with a for command like so:
for /f %%A in ('multiply.cmd !key! !message!') do set ciphertext=%%A
However, at numbers this size, it is not safe to do normal arithmetic operations. It should be treated as a string.

Mee
- 207
- 5
- 11
0
@ECHO OFF
SETLOCAL
SET "anum=333333333333333334"
SET "bnum=3"
CALL :longmult cnum anum bnum
ECHO %anum% * %bnum%=%cnum%
GOTO :EOF
:longmult
SETLOCAL ENABLEDELAYEDEXPANSION
SET "$=!%2!"
SET "$0=0"
FOR /l %%x IN (1,1,9) DO CALL :longadd $%%x $!$0! $&SET "$0=%%x"
SET "$0=0"
SET "$="
SET "$$=!%3!"
SET "$$$="
:mloop
CALL :longaddvr $ !$%$$:~-1%!%$$$% $
SET "$$$=%$$$%0"
SET "$$=%$$:~0,-1%
IF DEFINED $$ GOTO mloop
endlocal&SET "%1=%$%"
GOTO :eof
:: Longadd reference to reference
:longadd
SETLOCAL ENABLEDELAYEDEXPANSION
SET "p3=!%3!"
SET "p2=!%2!"
:: Have values to be added in P2,P3
:longacomm
SET "$="
SET /a $carry=0
:addloop
IF DEFINED p2 IF DEFINED p3 (
SET /a $carry=$carry+%p2:~-1%+%p3:~-1%
SET "p2=%p2:~0,-1%"
SET "p3=%p3:~0,-1%"
SET "$=!$carry:~-1!%$%"
SET /a $carry/=10
GOTO addloop
)
IF %$carry%==1 (
IF NOT DEFINED p2 SET /a p2=0
IF NOT DEFINED p3 SET /a p3=0
GOTO addloop
)
SET "$=%p2%%p3%%$%"
endlocal&SET "%1=%$%"
GOTO :eof
:: Longadd value to reference
:longaddvr
SETLOCAL ENABLEDELAYEDEXPANSION
SET "p3=!%3!"
SET "p2=%~2"
GOTO longacomm
Here's a routine to multiply the values of two variables giving a third.
How it works I'll leave as an exercise for those interested.

Magoo
- 77,302
- 8
- 62
- 84