Who does non-decimal bignums with floating radix point? - scripting

Nice as the Tcl libraries math::bignum and math::bigfloat are, the middle ground between the two needs to be addressed. Namely, bignums which are in different radices and have a radix point.
At present math::bignum only handles integers (afaict) and math::bigfloat won't let you specify different radices to math::bigfloat::fromstr (ditto).
Does anyone know of a library, for any of the major scripting languages (e.g. Tcl, Perl, Python, Ruby, Lua) or less major ones (newLISP for example), which implements bignums in different radices with handling for radix point?

bignumber.js is a Javascript library that handles numbers with a radix point in bases from 2 to 36.

I couldn't find any libraries for this, but I haven't looked for long.
But you can work around the problem similar to what you would do if you want 64-bit datatypes, but only 32-bit datatypes are available. With the libraries you already have, you should be able to represent a number in base b like this:
ABCDEF.GHIJKLMN
can be split to the two bignums ABCDEF and GHIJKLMN. GHIJKLMN in fact is representing GHIJLMN / pow(b, length(GHIJKLMN)) => GHIJKLM / pow(b, 8). Now you can overwrite the operators you need which should be possible for things like +, -, *, /. If you need more things like sqrt, log or pow, this workaround will get too complex and you should really look for a library.

Your best bet is to use GMP (libgmp).
I myself have looked long and hard for a .NET version without luck.

Related

Reverse a decryption algorithm with a given .exe GUI

I am using a Keygen application (.exe). There are two input fields in it's GUI:
p1 - at least 1 digit, 10 digits max - ^[0-9]{1,10}$
p2 - 12 chars max - uppercase letters/digits/underscores - ^[A-Z0-9_]{0,12}$
Pressing generate button produce a key x.
x - 20 digits exactly - ^[0-9]{20}$
For each pair (p1,p2), there is only one x (in other words: f(p1,p2) = x is a function)
I am interested in it's encryption algorithm.
Is there any way of reverse engineering the algorithm?
I thought of two ways:
decompiling. I used snowman, but the output is too polluted. The decompiled code probably contains non-relevant parts, such as the GUI.
analyzing of input and output. I wonder if there any option to determine the used encryption algorithm by analyzing a set of f(p1,p2) = x results.
As you mentioned, using snowman or some other decompiling tools is probably the way to go.
I doubt you would be able to determine the algorithm just by looking at the input output combinations, since it is possible to write any kind of arbitrary algorithm, that can behave in any way.
Perhaps you could just ask the author what algorithm they're using ?
Unless it's something really simple, I'd rule out your option 2 of trying to figure it out by looking at input and output pairs.
For decompiling / reverse engineering a static binary, you should first determine whether it's a .NET application or something else. If it's written in .NET you can try this for decompilation:
https://www.jetbrains.com/decompiler/
It's really easy to use, unless the binary has been obfuscated.
If the application is not a .NET application, you can try Ghidra and/or Cutter which both has pretty impressive decompilers built in:
https://ghidra-sre.org/
https://cutter.re/
If static code analysis is not enough, you can add a debugger to it. Ghidra and x64dbg work really well together, and can be synced via a plugin installed in both.
If you're new to this, I can recommend both that you look into basic assembler for the x86 platform so you have a general idea of how the CPU works. Another way to get started is "crackme" style challenges from CTF competitions. Often there great write-ups with the solution, so you have both the question and answer available.
Good luck!
Type in p1 and p2. Scan the process for that byte string. Then put a hardware breakpoint for memory access on it. Generate the key, it will hit that hardware breakpoint. Then you have the address which accesses it and start reversing from there in Ghidra(Don't forget to use BASE + OFFSET) since ghidra's output won't have the same base as the running application. The relevant code HAS to access the inputs. So you know where the algorithm is. Since it either directly accesses it, or somewhere within that call chain is accessed relatively fast. Nobody can know without actually seeing the executable.

How to print a character in an x,y coordinate in the console using kotlin?

I want achieve that to make a basic game
Is there any way to print a character in console in a x,y coordinate like gotoxy function in conio library of C language?
Just as with C, Java provides no built-in way to do full-screen terminal output.
And, as with C, you have two main options:
You could assume that the terminal understands ANSI escape codes, and output those directly.  That's quick-and-dirty; it doesn't require any dependencies, and the basics can be done fairly easily.  But it's not very maintainable; anything more sophisticated gets very fiddly — and, more importantly, it's likely to fail on other terminal types.
Or you could use a library which does all the hard work.  These questions ask about that, and have several answers.

Acess the SDPA-GMP solver from mpmath

I do have code in mpmath that does the main part of what i do, except soling a semidefinite programming in arbitrary precision.
For that, i might be able to use SDPA-GMP, a C++ piece of software that solves a SDP in arbitrary precision using GMP as base arbitrary precision library.
Do you know if there are possibilities to call this from python ? On the over hand, is there somewhere a converter that passed from mpmath objcts to gmp ?
You might have found a solution but here is one: you can use the interface PICOS, save the problem with the extension 'dat-s' and then feed that to SDPA-GMP. This works perfectly and it's rather easy to use.

perl5 code with (ignored) perl6 data types

I want to start prepping some perl5 code for perl6. in particular, I like the idea of declaring what types my variables are supposed to be. perl6 defines Bool, Int, Array, Hash, Num, Complex, Pair, and Str. So I would in essence like to do the equivalent of a C preprocessor #define Int /**/ for now. It would be even better if it would check the data type, but I can live without it.
Easy? Hard? Impossible?
You would have to write a parser that can parse Perl 5. Unless your code is fairly simple, that's pretty high on the hardness scale.
Also, I found that I structure Perl 6 programs very much different from Perl 5 code. You can technically stay very close to 1:1 one a line by line basis when porting Perl 5 to Perl 6 but the result wont be idiomatic, slow and hard to maintain when you fully switch to Perl 6. Just adding empty macros will not help you much because every mistake you make is just ignored. That may actually increase the burden when you want to port the program for good.
The idea has appeal but you may just increase your workload for no real gain.
There are several Perl 5 modules that go into that direction. For object orientation you can use Moose and MooseX::Method::Signatures.
For declaring subs and methods there is Method::Signatures, Sub::Signatures and Kavorka.
Also look in the Perl6namespace on CPAN.

Say I didn't like the syntax of objC blocks... (or: how to customize llvm a little bit)

...is there anything I could do about it?
To be more precise, I would like to replace the caret "^" with something like "§" - granted, there's not much left on the keyboard that's not in use already.
After thinking about it for a while (dismissed using run script build phases along the way) I think the only way to do it would be a custom llvm build.
While I don't quite think I'm ready to deal with the internals of compilers, I have the naive hope that replacing one symbol with another isn't too hard. And the idea of building and running my own version of a compiler tickles me, be it just for a good deal of childish fun.
So I started poking around in the llvm sources, but - surprise - got nowhere so far.
If someone is familiar with these kind of things, could you please point me to a place to look at?
That would be awesome! Thanks!
Extending LLVM can be a bit of a hassle, especially considering how fast-moving the compiler team is, so it's a good thing you don't have to. The C preprocessor exists to perform the exact same thing you've outlined (text replacement). I'm fairly sure § isn't aliased to anything important, so #define § ^ should work great. If you still want to write your own module, LLVM provides instructions on how to extend their compiler.
Actually the code relevant for such a change isn't a part of LLVM at all, but a part of its Objective-C frontend, called Clang. Confusingly, "Clang" is also the name of the entire C/C++/ObjC compiler based on both Clang and LLVM.
While I don't quite think I'm ready to deal with the internals of compilers, I have the naive hope that replacing one symbol with another isn't too hard.
And you'll be right. What you're trying to do is very simple change.
In fact, if ^ was only used for blocks, it would be a trivial change - just modify the lexer to generate the "caret" token from § instead of ^: take a look at the lexer code to see what I mean (search for ^).
Unfortunately it's used for xor as well, so we'll have to modify both the lexer and the parser. The lexer to add a new token type and create that token from §, the parser to actually do something with it, e.g. by adding:
case tok::section: // 'section' is the token type you've added
Res = ParseBlockLiteralExpression();
break;
(and then fixing the assert at the beginning of ParseBlockLiteralExpression()).
You might run into some issues, though, as § isn't in ASCII - though as far as I know Clang should be able to deal with UTF-8 encoded files.