Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Integers into parser and solvers #36

Merged
merged 11 commits into from
Nov 13, 2022
Merged

Add Integers into parser and solvers #36

merged 11 commits into from
Nov 13, 2022

Conversation

FissoreD
Copy link
Collaborator

@FissoreD FissoreD commented Nov 8, 2022

Breif summary:

  1. Added Integer to parser -> They are surrounded by ticks (eg '45')
  2. Add CryptaConstant class to represent a node in the tree containing an integer (it extends CryptaLeaf) and adds some methods:
    • getConstant to obtain the constant stored in it (it is in base 10)
    • changeBaseLittleEndian(int) -> returns the constant in the wanted base on the form of a integer list in little endian
  3. Add isConstant method to ICryptaNode, it is a shortcut to instantof
  4. Update CryptaBigNumModeler to represent in the correct base the constants and add them to the stack
  5. For every modified or added methods, tests have been added
  6. Upgraded Java version to 17 (readme to be updated), in order to have enhanced switch and pattern matching in instanceof.

Now we are able to parse and analyse long multiplications (see here) and long divisions (see here)

FissoreD and others added 8 commits November 3, 2022 21:21
- added class CryptaConstant extending CryptaLeaf
- test long multiplication
- update all classes so that integers are treated as constants and in evaluation case are not added in the map of symbols
- we can do long multiplications, there is a test for that taken from issue #22
```
  SEE *
   SO =
-----
 EMOO +
MESS  =
------
MIMEO
```
- test on long division
- other thest have been taken from http://cryptarithms.awardspace.us/puzzles.html

TODO : test for BigNum and add more tests for basic cases expecially negative tests
- Added method in CryptaConstant to convert decimal integer to integer in a given base in LittleEndian
- BigNumModeler corrected method to add right integer to model in the wanted base (from config.arithBase)
- Added tests on bignum with integers
- Added tests with base change (both for bignum and normal solver)
Copy link
Owner

@arnaud-m arnaud-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • We must next check the formatting issue.
  • Tests are good.

We must solve the issue related to constants:

  • The word is enclosed by ticks.
  • The number is not.

A simple solution is to define two methods :

  • getWord without ticks
  • formatWord with ticks.

There may be more elegant solution

src/main/java/cryptator/solver/AdaptiveSolver.java Outdated Show resolved Hide resolved
src/main/java/cryptator/specs/ICryptaNode.java Outdated Show resolved Hide resolved

@Override
public void accept(ICryptaNode node, int numNode) {
if (node.isLeaf() && !node.isConstant()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the helper function.

}

private static void writeWord(ICryptaNode node, PrintWriter out) {
if (node.isConstant()) out.write("'");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be the node that adds the ticks ?

try {
BigInteger v = BigInteger.ZERO;
final BigInteger b = BigInteger.valueOf(base);
if (node instanceof CryptaConstant constant)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have chosen to add an attribute to the class.
Do not use both the attribute and instanceof.

I know that it allows to access the getConstant method, but we must find another way.

@arnaud-m arnaud-m merged commit 34eafc9 into main Nov 13, 2022
@arnaud-m arnaud-m deleted the addIntegers branch November 13, 2022 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants