-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 276779e..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..177a4d0
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,99 @@
+# Changelog EnigmAndroid
+
+## v1.0.2-01.01.2019
+### Changes
+* Added support for fastlane metadata
+* Remove What's new dialog
+
+## v1.0.1-12.01.2018
+### Changes
+* Added language: Brazilian-Portuguese
+
+## v1.0.0-05.05.2017
+### Changes
+* Added Enigma KD
+* Added "protocol version" to QR-Code-shared configuration strings.
+ This breaks backwards compatibility to older versions, but I added it to enable backwards compatibility in upcoming releases.
+* Configurations can now be shared to EnigmAndroid as text
+* Moved preference management to SettingsActivity
+* Added dialog to choose whether to share configuration via text or via QR-code
+* Same for receiving
+* Added TextBox to configuration-share-dialog that lets the user see and copy the
+ configuration string.
+* Added Whats-new-Dialog
+* New Icon!
+* Added Script to automatically generate icons
+* Reformatted code
+### TODO
+* Add tips on long clicks at parts
+* Move KD right below K
+* Add intent filters to recognize and automatically handle shared/copied configuration Strings .These are Strings starting with "EnigmAndroid/"
+* Write tests to ensure correct functionality (Pull Requests welcome)
+* Add multi-Enigma (select any rotor/reflector etc. Probably wont happen too soon)
+
+## v0.1.9-09.10.2015
+### Changes
+* Added option to share/receive configurations via QR-Code (ZXing Barcode Scanner)
+* Prevent user from setting incomplete reflector wiring
+* Add option to generate configuration from passphrase
+* Reworked Enigma definition (available Rotors/Reflectors/ Entrywheels
+* Completely verified correct functionality of Enigma T
+* Added number spelling in spanish, italian
+* Added backwards compatibility to API level 10 (Gingerbread 2.3.3)
+
+## v0.1.8-27.09.2015
+### Changes
+* Added Enigma G31
+* Added Enigma G312
+* Added Enigma G260
+* Replaced Enigma K with Enigma K, K (Swiss) and K (Swiss, Airforce)
+* Added Enigma R
+* Changed identifiers of enigma models
+* Changed landscape layout of enigma model d
+* Updated the about-dialog text.
+* Shortened EnigmaStateBundle
+* Added different colors to the plugboard-/pluggable reflector dialog. This helps to differentiate connections.
+* Reworked InputPreparer using decorator pattern and added options to customize input preparation
+* Reworked Reflector-/Rotor creation/management
+* Added Button to set the Enigma into a random configuration
+
+## v0.1.7-15.09.2015
+### Changes
+* Added Enigma K
+* Added Enigma T
+* Created Plugboard-/pluggable Reflector-Setting-Dialog
+
+## v0.1.6-10.09.2015
+### Changes
+* Fixed about dialog (outdated manual)
+* Updated CHANGELOG (oops)
+* Added Enigma D
+* Added rotor names to ringSettingsDialog
+* Reworked major parts of the app once again :)
+* Added option to break messages up into blocks
+
+## v0.1.5-27.08.2015
+### Changes
+* Added french number spelling
+* Added Enigma Models M3, M4
+* Added option to select different enigma models into options menu
+* Added developer class for simple rotor creation (not a feature in the app)
+* Fixed broken ring settings
+* Fixed false reset of ring settings when switching from/to landscape mode
+
+## v0.1.4-15.08.2015
+### Changes
+* Reworked the core implementation to follow some principals of Software Engineering
+* Fixed some layout issues
+* Fixed anomaly for step by step inputs
+* Added send/receive text functionality
+* added missing licenses to class files
+* Added proper documentation
+* Extended input interpretation (number spelling in different languages, any unknown special character now becomes 'X'
+
+## v0.1.3-14.03.2015
+### Changes
+* Added About Dialog with ChangeLog-Button
+* Moved Version Info into About Dialog
+* Updated License Files
+* Fixed Landscape Layout
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
deleted file mode 100644
index 7d6933b..0000000
--- a/CHANGELOG.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-CHANGELOG ENIGMANDROID
-
-v0.1.3-14.03.2015<
-*Added About Dialog with ChangeLog-Button
-*Moved Version Info into About Dialog
-*Updated License Files
-*Fixed Landscape Layout
\ No newline at end of file
diff --git a/EnigmAndroid.iml b/EnigmAndroid.iml
deleted file mode 100644
index 0bb6048..0000000
--- a/EnigmAndroid.iml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/License.md b/License.md
index 77db3e0..97abe6d 100644
--- a/License.md
+++ b/License.md
@@ -1,280 +1,676 @@
-GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Lesser General Public License instead.) You can apply it to
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+ TERMS AND CONDITIONS
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
+ 0. Definitions.
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
+ "This License" refers to version 3 of the GNU General Public License.
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
+ 1. Source Code.
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
+ The Corresponding Source for a work in source code form is that
+same work.
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
+ 2. Basic Permissions.
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
this License.
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
+ 13. Use with the GNU Affero General Public License.
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
+ 14. Revised Versions of this License.
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
- NO WARRANTY
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
+ 15. Disclaimer of Warranty.
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ {one line to give the program's name and a brief idea of what it does.}
+ Copyright (C) {year} {name of author}
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ {project} Copyright (C) {year} {fullname}
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+.
- END OF TERMS AND CONDITIONS
\ No newline at end of file
diff --git a/README.md b/README.md
index 4b380c1..96af7cf 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,24 @@
# EnigmAndroid
-Android implementation of the famous Enigma machine
+
+
+[](https://f-droid.org/app/de.vanitasvitae.enigmandroid)
+
+Android implementation of the famous Enigma machine.
+
+Check out the website at [Jabberhead.tk](https://blog.jabberhead.tk/EnigmAndroid/).
+
+## Screenshots
+
+
+
+
+
+
+
+
+
+
+
+If you want to support me with a donation, feel free to do so :)
+
+btc: 1MW2DobbNFfcjxTSYzJhtkmiNS7efwaWFX
diff --git a/app/.gitignore b/app/.gitignore
index 796b96d..fa69b30 100644
--- a/app/.gitignore
+++ b/app/.gitignore
@@ -1 +1,4 @@
/build
+/src/main/java/de/vanitasvitae/enigmandroid/enigma/util/
+/src/androidTest/
+/src/main/res/render-icon.sh
diff --git a/app/app-release.apk b/app/app-release.apk
deleted file mode 100644
index fc7dba4..0000000
Binary files a/app/app-release.apk and /dev/null differ
diff --git a/app/app.iml b/app/app.iml
deleted file mode 100644
index 2459d0c..0000000
--- a/app/app.iml
+++ /dev/null
@@ -1,92 +0,0 @@
-
-
-
-
-
-
To integrate, create an instance of {@code IntentIntegrator} and call {@link #initiateScan()} and wait
+ * for the result in your app.
+ *
+ *
It does require that the Barcode Scanner (or work-alike) application is installed. The
+ * {@link #initiateScan()} method will prompt the user to download the application, if needed.
+ *
+ *
There are a few steps to using this integration. First, your {@link Activity} must implement
+ * the method {@link Activity#onActivityResult(int, int, Intent)} and include a line of code like this:
+ *
+ *
{@code
+ * public void onActivityResult(int requestCode, int resultCode, Intent intent) {
+ * IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
+ * if (scanResult != null) {
+ * // handle scan result
+ * }
+ * // else continue with any other code you need in the method
+ * ...
+ * }
+ * }
+ *
+ *
This is where you will handle a scan result.
+ *
+ *
Second, just call this in response to a user action somewhere to begin the scan process:
Note that {@link #initiateScan()} returns an {@link AlertDialog} which is non-null if the
+ * user was prompted to download the application. This lets the calling app potentially manage the dialog.
+ * In particular, ideally, the app dismisses the dialog if it's still active in its {@link Activity#onPause()}
+ * method.
+ *
+ *
You can use {@link #setTitle(String)} to customize the title of this download prompt dialog (or, use
+ * {@link #setTitleByID(int)} to set the title by string resource ID.) Likewise, the prompt message, and
+ * yes/no button labels can be changed.
+ *
+ *
Finally, you can use {@link #addExtra(String, Object)} to add more parameters to the Intent used
+ * to invoke the scanner. This can be used to set additional options not directly exposed by this
+ * simplified API.
+ *
+ *
By default, this will only allow applications that are known to respond to this intent correctly
+ * do so. The apps that are allowed to response can be set with {@link #setTargetApplications(List)}.
+ * For example, set to {@link #TARGET_BARCODE_SCANNER_ONLY} to only target the Barcode Scanner app itself.
+ *
+ *
Sharing text via barcode
+ *
+ *
To share text, encoded as a QR Code on-screen, similarly, see {@link #shareText(CharSequence)}.
+ *
+ *
Some code, particularly download integration, was contributed from the Anobiit application.
+ *
+ *
Enabling experimental barcode formats
+ *
+ *
Some formats are not enabled by default even when scanning with {@link #ALL_CODE_TYPES}, such as
+ * PDF417. Use {@link #initiateScan(java.util.Collection)} with
+ * a collection containing the names of formats to scan for explicitly, like "PDF_417", to use such
+ * formats.
+ *
+ * @author Sean Owen
+ * @author Fred Lin
+ * @author Isaac Potoczny-Jones
+ * @author Brad Drehmer
+ * @author gcstang
+ */
+public class IntentIntegrator {
+
+ public static final int REQUEST_CODE = 0x0000c0de; // Only use bottom 16 bits
+ private static final String TAG = IntentIntegrator.class.getSimpleName();
+
+ public static final String DEFAULT_TITLE = "Install Barcode Scanner?";
+ public static final String DEFAULT_MESSAGE =
+ "This application requires Barcode Scanner. Would you like to install it?";
+ public static final String DEFAULT_YES = "Yes";
+ public static final String DEFAULT_NO = "No";
+
+ private static final String BS_PACKAGE = "com.google.zxing.client.android";
+ private static final String BSPLUS_PACKAGE = "com.srowen.bs.android";
+
+ // supported barcode formats
+ public static final Collection PRODUCT_CODE_TYPES = list("UPC_A", "UPC_E", "EAN_8", "EAN_13", "RSS_14");
+ public static final Collection ONE_D_CODE_TYPES =
+ list("UPC_A", "UPC_E", "EAN_8", "EAN_13", "CODE_39", "CODE_93", "CODE_128",
+ "ITF", "RSS_14", "RSS_EXPANDED");
+ public static final Collection QR_CODE_TYPES = Collections.singleton("QR_CODE");
+ public static final Collection DATA_MATRIX_TYPES = Collections.singleton("DATA_MATRIX");
+
+ public static final Collection ALL_CODE_TYPES = null;
+
+ public static final List TARGET_BARCODE_SCANNER_ONLY = Collections.singletonList(BS_PACKAGE);
+ public static final List TARGET_ALL_KNOWN = list(
+ BSPLUS_PACKAGE, // Barcode Scanner+
+ BSPLUS_PACKAGE + ".simple", // Barcode Scanner+ Simple
+ BS_PACKAGE // Barcode Scanner
+ // What else supports this intent?
+ );
+
+ private final Activity activity;
+ private final Fragment fragment;
+
+ private String title;
+ private String message;
+ private String buttonYes;
+ private String buttonNo;
+ private List targetApplications;
+ private final Map moreExtras = new HashMap<>(3);
+
+ /**
+ * @param activity {@link Activity} invoking the integration
+ */
+ public IntentIntegrator(Activity activity) {
+ this.activity = activity;
+ this.fragment = null;
+ initializeConfiguration();
+ }
+
+ /**
+ * @param fragment {@link Fragment} invoking the integration.
+ * {@link #startActivityForResult(Intent, int)} will be called on the {@link Fragment} instead
+ * of an {@link Activity}
+ */
+ public IntentIntegrator(Fragment fragment) {
+ this.activity = fragment.getActivity();
+ this.fragment = fragment;
+ initializeConfiguration();
+ }
+
+ private void initializeConfiguration() {
+ title = DEFAULT_TITLE;
+ message = DEFAULT_MESSAGE;
+ buttonYes = DEFAULT_YES;
+ buttonNo = DEFAULT_NO;
+ targetApplications = TARGET_ALL_KNOWN;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public void setTitleByID(int titleID) {
+ title = activity.getString(titleID);
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public void setMessageByID(int messageID) {
+ message = activity.getString(messageID);
+ }
+
+ public String getButtonYes() {
+ return buttonYes;
+ }
+
+ public void setButtonYes(String buttonYes) {
+ this.buttonYes = buttonYes;
+ }
+
+ public void setButtonYesByID(int buttonYesID) {
+ buttonYes = activity.getString(buttonYesID);
+ }
+
+ public String getButtonNo() {
+ return buttonNo;
+ }
+
+ public void setButtonNo(String buttonNo) {
+ this.buttonNo = buttonNo;
+ }
+
+ public void setButtonNoByID(int buttonNoID) {
+ buttonNo = activity.getString(buttonNoID);
+ }
+
+ public Collection getTargetApplications() {
+ return targetApplications;
+ }
+
+ public final void setTargetApplications(List targetApplications) {
+ if (targetApplications.isEmpty()) {
+ throw new IllegalArgumentException("No target applications");
+ }
+ this.targetApplications = targetApplications;
+ }
+
+ public void setSingleTargetApplication(String targetApplication) {
+ this.targetApplications = Collections.singletonList(targetApplication);
+ }
+
+ public Map getMoreExtras() {
+ return moreExtras;
+ }
+
+ public final void addExtra(String key, Object value) {
+ moreExtras.put(key, value);
+ }
+
+ /**
+ * Initiates a scan for all known barcode types with the default camera.
+ *
+ * @return the {@link AlertDialog} that was shown to the user prompting them to download the app
+ * if a prompt was needed, or null otherwise.
+ */
+ public final AlertDialog initiateScan() {
+ return initiateScan(ALL_CODE_TYPES, -1);
+ }
+
+ /**
+ * Initiates a scan for all known barcode types with the specified camera.
+ *
+ * @param cameraId camera ID of the camera to use. A negative value means "no preference".
+ * @return the {@link AlertDialog} that was shown to the user prompting them to download the app
+ * if a prompt was needed, or null otherwise.
+ */
+ public final AlertDialog initiateScan(int cameraId) {
+ return initiateScan(ALL_CODE_TYPES, cameraId);
+ }
+
+ /**
+ * Initiates a scan, using the default camera, only for a certain set of barcode types, given as strings corresponding
+ * to their names in ZXing's {@code BarcodeFormat} class like "UPC_A". You can supply constants
+ * like {@link #PRODUCT_CODE_TYPES} for example.
+ *
+ * @param desiredBarcodeFormats names of {@code BarcodeFormat}s to scan for
+ * @return the {@link AlertDialog} that was shown to the user prompting them to download the app
+ * if a prompt was needed, or null otherwise.
+ */
+ public final AlertDialog initiateScan(Collection desiredBarcodeFormats) {
+ return initiateScan(desiredBarcodeFormats, -1);
+ }
+
+ /**
+ * Initiates a scan, using the specified camera, only for a certain set of barcode types, given as strings corresponding
+ * to their names in ZXing's {@code BarcodeFormat} class like "UPC_A". You can supply constants
+ * like {@link #PRODUCT_CODE_TYPES} for example.
+ *
+ * @param desiredBarcodeFormats names of {@code BarcodeFormat}s to scan for
+ * @param cameraId camera ID of the camera to use. A negative value means "no preference".
+ * @return the {@link AlertDialog} that was shown to the user prompting them to download the app
+ * if a prompt was needed, or null otherwise
+ */
+ public final AlertDialog initiateScan(Collection desiredBarcodeFormats, int cameraId) {
+ Intent intentScan = new Intent(BS_PACKAGE + ".SCAN");
+ intentScan.addCategory(Intent.CATEGORY_DEFAULT);
+
+ // check which types of codes to scan for
+ if (desiredBarcodeFormats != null) {
+ // set the desired barcode types
+ StringBuilder joinedByComma = new StringBuilder();
+ for (String format : desiredBarcodeFormats) {
+ if (joinedByComma.length() > 0) {
+ joinedByComma.append(',');
+ }
+ joinedByComma.append(format);
+ }
+ intentScan.putExtra("SCAN_FORMATS", joinedByComma.toString());
+ }
+
+ // check requested camera ID
+ if (cameraId >= 0) {
+ intentScan.putExtra("SCAN_CAMERA_ID", cameraId);
+ }
+
+ String targetAppPackage = findTargetAppPackage(intentScan);
+ if (targetAppPackage == null) {
+ return showDownloadDialog();
+ }
+ intentScan.setPackage(targetAppPackage);
+ intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
+ attachMoreExtras(intentScan);
+ startActivityForResult(intentScan, REQUEST_CODE);
+ return null;
+ }
+
+ /**
+ * Start an activity. This method is defined to allow different methods of activity starting for
+ * newer versions of Android and for compatibility library.
+ *
+ * @param intent Intent to start.
+ * @param code Request code for the activity
+ * @see android.app.Activity#startActivityForResult(Intent, int)
+ * @see android.app.Fragment#startActivityForResult(Intent, int)
+ */
+ protected void startActivityForResult(Intent intent, int code) {
+ if (fragment == null) {
+ activity.startActivityForResult(intent, code);
+ } else {
+ fragment.startActivityForResult(intent, code);
+ }
+ }
+
+ private String findTargetAppPackage(Intent intent) {
+ PackageManager pm = activity.getPackageManager();
+ List availableApps = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
+ if (availableApps != null) {
+ for (String targetApp : targetApplications) {
+ if (contains(availableApps, targetApp)) {
+ return targetApp;
+ }
+ }
+ }
+ return null;
+ }
+
+ private static boolean contains(Iterable availableApps, String targetApp) {
+ for (ResolveInfo availableApp : availableApps) {
+ String packageName = availableApp.activityInfo.packageName;
+ if (targetApp.equals(packageName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private AlertDialog showDownloadDialog() {
+ AlertDialog.Builder downloadDialog = new AlertDialog.Builder(activity);
+ downloadDialog.setTitle(title);
+ downloadDialog.setMessage(message);
+ downloadDialog.setPositiveButton(buttonYes, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ String packageName;
+ if (targetApplications.contains(BS_PACKAGE)) {
+ // Prefer to suggest download of BS if it's anywhere in the list
+ packageName = BS_PACKAGE;
+ } else {
+ // Otherwise, first option:
+ packageName = targetApplications.get(0);
+ }
+ Uri uri = Uri.parse("market://details?id=" + packageName);
+ Intent intent = new Intent(Intent.ACTION_VIEW, uri);
+ try {
+ if (fragment == null) {
+ activity.startActivity(intent);
+ } else {
+ fragment.startActivity(intent);
+ }
+ } catch (ActivityNotFoundException anfe) {
+ // Hmm, market is not installed
+ Log.w(TAG, "Google Play is not installed; cannot install " + packageName);
+ }
+ }
+ });
+ downloadDialog.setNegativeButton(buttonNo, null);
+ downloadDialog.setCancelable(true);
+ return downloadDialog.show();
+ }
+
+
+ /**
+ *
Call this from your {@link Activity}'s
+ * {@link Activity#onActivityResult(int, int, Intent)} method.
+ *
+ * @param requestCode request code from {@code onActivityResult()}
+ * @param resultCode result code from {@code onActivityResult()}
+ * @param intent {@link Intent} from {@code onActivityResult()}
+ * @return null if the event handled here was not related to this class, or
+ * else an {@link IntentResult} containing the result of the scan. If the user cancelled scanning,
+ * the fields will be null.
+ */
+ public static IntentResult parseActivityResult(int requestCode, int resultCode, Intent intent) {
+ if (requestCode == REQUEST_CODE) {
+ if (resultCode == Activity.RESULT_OK) {
+ String contents = intent.getStringExtra("SCAN_RESULT");
+ String formatName = intent.getStringExtra("SCAN_RESULT_FORMAT");
+ byte[] rawBytes = intent.getByteArrayExtra("SCAN_RESULT_BYTES");
+ int intentOrientation = intent.getIntExtra("SCAN_RESULT_ORIENTATION", Integer.MIN_VALUE);
+ Integer orientation = intentOrientation == Integer.MIN_VALUE ? null : intentOrientation;
+ String errorCorrectionLevel = intent.getStringExtra("SCAN_RESULT_ERROR_CORRECTION_LEVEL");
+ return new IntentResult(contents,
+ formatName,
+ rawBytes,
+ orientation,
+ errorCorrectionLevel);
+ }
+ return new IntentResult();
+ }
+ return null;
+ }
+
+
+ /**
+ * Defaults to name "TEXT_TYPE".
+ *
+ * @param text the text string to encode as a barcode
+ * @return the {@link AlertDialog} that was shown to the user prompting them to download the app
+ * if a prompt was needed, or null otherwise
+ * @see #shareText(CharSequence, CharSequence)
+ */
+ public final AlertDialog shareText(CharSequence text) {
+ return shareText(text, "TEXT_TYPE");
+ }
+
+ /**
+ * Shares the given text by encoding it as a barcode, such that another user can
+ * scan the text off the screen of the device.
+ *
+ * @param text the text string to encode as a barcode
+ * @param type name of data to encode. See {@code com.google.zxing.client.android.Contents.Type} constants.
+ * @return the {@link AlertDialog} that was shown to the user prompting them to download the app
+ * if a prompt was needed, or null otherwise
+ */
+ public final AlertDialog shareText(CharSequence text, CharSequence type) {
+ Intent intent = new Intent();
+ intent.addCategory(Intent.CATEGORY_DEFAULT);
+ intent.setAction(BS_PACKAGE + ".ENCODE");
+ intent.putExtra("ENCODE_TYPE", type);
+ intent.putExtra("ENCODE_DATA", text);
+ String targetAppPackage = findTargetAppPackage(intent);
+ if (targetAppPackage == null) {
+ return showDownloadDialog();
+ }
+ intent.setPackage(targetAppPackage);
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
+ attachMoreExtras(intent);
+ if (fragment == null) {
+ activity.startActivity(intent);
+ } else {
+ fragment.startActivity(intent);
+ }
+ return null;
+ }
+
+ private static List list(String... values) {
+ return Collections.unmodifiableList(Arrays.asList(values));
+ }
+
+ private void attachMoreExtras(Intent intent) {
+ for (Map.Entry entry : moreExtras.entrySet()) {
+ String key = entry.getKey();
+ Object value = entry.getValue();
+ // Kind of hacky
+ if (value instanceof Integer) {
+ intent.putExtra(key, (Integer) value);
+ } else if (value instanceof Long) {
+ intent.putExtra(key, (Long) value);
+ } else if (value instanceof Boolean) {
+ intent.putExtra(key, (Boolean) value);
+ } else if (value instanceof Double) {
+ intent.putExtra(key, (Double) value);
+ } else if (value instanceof Float) {
+ intent.putExtra(key, (Float) value);
+ } else if (value instanceof Bundle) {
+ intent.putExtra(key, (Bundle) value);
+ } else {
+ intent.putExtra(key, value.toString());
+ }
+ }
+ }
+
+}
diff --git a/app/src/main/java/com/google/zxing/integration/android/IntentResult.java b/app/src/main/java/com/google/zxing/integration/android/IntentResult.java
new file mode 100644
index 0000000..9e452fb
--- /dev/null
+++ b/app/src/main/java/com/google/zxing/integration/android/IntentResult.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2009 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.zxing.integration.android;
+
+/**
+ *
Encapsulates the result of a barcode scan invoked through {@link IntentIntegrator}.
+ *
+ * @author Sean Owen
+ */
+public final class IntentResult {
+
+ private final String contents;
+ private final String formatName;
+ private final byte[] rawBytes;
+ private final Integer orientation;
+ private final String errorCorrectionLevel;
+
+ IntentResult() {
+ this(null, null, null, null, null);
+ }
+
+ IntentResult(String contents,
+ String formatName,
+ byte[] rawBytes,
+ Integer orientation,
+ String errorCorrectionLevel) {
+ this.contents = contents;
+ this.formatName = formatName;
+ this.rawBytes = rawBytes;
+ this.orientation = orientation;
+ this.errorCorrectionLevel = errorCorrectionLevel;
+ }
+
+ /**
+ * @return raw content of barcode
+ */
+ public String getContents() {
+ return contents;
+ }
+
+ /**
+ * @return name of format, like "QR_CODE", "UPC_A". See {@code BarcodeFormat} for more format names.
+ */
+ public String getFormatName() {
+ return formatName;
+ }
+
+ /**
+ * @return raw bytes of the barcode content, if applicable, or null otherwise
+ */
+ public byte[] getRawBytes() {
+ return rawBytes;
+ }
+
+ /**
+ * @return rotation of the image, in degrees, which resulted in a successful scan. May be null.
+ */
+ public Integer getOrientation() {
+ return orientation;
+ }
+
+ /**
+ * @return name of the error correction level used in the barcode, if applicable
+ */
+ public String getErrorCorrectionLevel() {
+ return errorCorrectionLevel;
+ }
+
+ @Override
+ public String toString() {
+ int rawBytesLength = rawBytes == null ? 0 : rawBytes.length;
+ return "Format: "+formatName+'\n'+"Contents: "+contents+'\n'+"Raw bytes: ("+rawBytesLength+" bytes)\n"+"Orientation: "+orientation+'\n'+"EC level: "+errorCorrectionLevel+'\n';
+ }
+
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/Enigma.java b/app/src/main/java/de/vanitasvitae/enigmandroid/Enigma.java
deleted file mode 100644
index 4b804ca..0000000
--- a/app/src/main/java/de/vanitasvitae/enigmandroid/Enigma.java
+++ /dev/null
@@ -1,397 +0,0 @@
-package de.vanitasvitae.enigmandroid;
-
-
-/**
- * Enigma-machine
- *Copyright (C) 2015 Paul Schaub
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- * @author vanitasvitae
- */
-public class Enigma
-{
- private Plugboard plugboard;
-
- //Slots for the rotors
- private Rotor r1;
- private Rotor r2;
- private Rotor r3;
- //Slot for the reflector
- private Rotor reflector;
- private boolean prefAnomaly; //Do you want to simulate the anomaly?
- private boolean anomaly; //Is it time to spin twice?
- //Standard configuration (rotors 1-3, reflector B, all three rotors set to position 1, rings too)
- public static final int[] STANDARD_CONFIGURATION = {1, 2, 3, 2, 1, 1, 1, 0, 0, 0};
-
- /**
- * Create new Enigma with given configuration.
- * If pbconf == null no plugs will be set (no scrambling in the plugboard).
- * If conf == null the enigma will be set to STANDARD_CONFIGURATION.
- *
- * @param pbconf two-dimensional array containing the chars symbolizing plugs that need to be switched over.
- * @param conf configuration of the enigma (a,b,c,d,e,f,g - a-c rotors, d reflector, e-g positions of the rotors)
- */
- public Enigma(char[][] pbconf, int[] conf) throws Plugboard.PlugAlreadyUsedException
- {
- if (conf != null) setConfiguration(conf);
- else setConfiguration(Enigma.STANDARD_CONFIGURATION);
-
- this.setPlugboard(pbconf);
- }
-
- /**
- * Encrypt / Decrypt a given String
- *
- * @param w Text to decrypt/encrypt
- * @return encrypted/decrypted string
- */
- public String encrypt(String w)
- {
- //output string
- String c = "";
- //for each char x in k
- for (int i = 0; i < w.length(); i++)
- {
- char x = w.charAt(i);
- //encrypt char
- c = c + this.encryptChar(x);
- }
- //return en-/decrypted string
- return c;
- }
-
- /**
- * Perform crypto on char.
- * Beforehand rotate rotors. Also implement the rotor anomaly.
- *
- * @param k input char
- * @return output char
- */
- public char encryptChar(char k)
- {
- //Rotate rotors
- r1.incrementCounter();
- if (r1.isAtTurnoverPosition() || (this.anomaly && prefAnomaly))
- {
- r2.incrementCounter();
- //Handle Anomaly
- this.anomaly = r2.doubleTurnAnomaly();
- if (r2.isAtTurnoverPosition())
- {
- r3.incrementCounter();
- }
- }
- int x = (int) k;
- x = x - 65; //Remove Unicode Offset (A=65 in Unicode.)
-
- //Encryption
- //forward direction
- x = plugboard.encrypt(x);
- x = (x + r1.getCounter()) % 26;
- x = r1.encryptForward(x);
- x = (x + r2.getCounter() - r1.getCounter()) % 26;
- x = r2.encryptForward(x);
- x = (x + r3.getCounter() - r2.getCounter()) % 26;
- x = r3.encryptForward(x);
- x = (26 + x - r3.getCounter()) % 26;
- //backward direction
- x = reflector.encryptForward(x);
- x = (26 + x + r3.getCounter()) % 26;
- x = r3.encryptBackward(x);
- x = (26 + x - r3.getCounter() + r2.getCounter()) % 26;
- x = r2.encryptBackward(x);
- x = (26 + x - r2.getCounter() + r1.getCounter()) % 26;
- x = r1.encryptBackward(x);
- x = (26 + x - r1.getCounter()) % 26;
- x = plugboard.encrypt(x);
-
- return (char) (x + 65); //Add Offset
- }
-
- /**
- * Prepare String for encryption via enigma
- * Replace . , ! ? : with X
- * Remove all other chars that are not A..Z
- *
- * @param word string
- * @return prepared string
- */
- public static String prepare(String word)
- {
- String w = word.toUpperCase();
- String c = "";
- for (int i = 0; i < w.length(); i++)
- {
- char x = w.charAt(i);
- if (x >= 65 && x <= 90) //If x in [A..Z]
- {
- c = c + x; //Append to String
- }
- //if x is special symbol
- else
- {
- if (x == '.' || x == ',' || x == '!' || x == '?' || x == ':')
- {
- //replace x with X and encrypt
- c = c + 'X';
- }
- }
- }
- return c;
- }
-
- /**
- * Create Plugboard configuration from String.
- * String must be in format XY,AZ and so on.
- * X and Y are plugs, that will be switched over.
- * Don't use plugs twice such as in AA or AB,CA. This will cause Exceptions.
- *
- * @param p String
- * @return Array containing plugboard configuration
- */
- public static char[][] parsePlugs(String p) throws InvalidPlugboardConfigurationFormatException
- {
- p = p.toUpperCase();
- //Check, if empty
- if (p.length() == 0)
- {
- return null;
- }
- //Ensure uppercase and split string
- String[] in = p.toUpperCase().split(",");
-
- //Check, whether input have had a correct length. Length+1 divided by 3 should be exactly how much fields there are in the array.
- //(2 chars or 2 chars followed by any times a comma and two chars)
- if (in.length != (p.length() + 1) / 3)
- {
- throw new InvalidPlugboardConfigurationFormatException("Error parsing plugs! Maybe you missed a ','?");
- } else
- {
- //Create new 2 dimensional array for pairs of plugs
- char[][] plugs = new char[(p.length() + 1) / 3][2];
- //Fill the array
- int i = 0;
- for (String x : in)
- {
- //Check, whether string is not representing a pair
- if (x.length() != 2)
- {
- throw new InvalidPlugboardConfigurationFormatException("Error parsing plugs! Maybe you didn't enter a pair somewhere?");
- }
- //If it does
- else
- {
- char[] pair = x.toCharArray();
- //Check, if Plugs are in alphabet
- if(pair[0]<65 || pair[1]<65 || pair[0]>90 || pair[1]>90) throw new InvalidPlugboardConfigurationFormatException("Error parsing plugs! Maybe you entered a number or a special character?");
- else
- {
- //add it to the array
- plugs[i] = pair;
- i++;
- }
- }
- }
- return plugs;
- }
- }
-
- /**
- * Set the plugboard to a new created object and set the configuration
- *
- * @param c configuration
- * @throws Plugboard.PlugAlreadyUsedException
- */
- public void setPlugboard(char[][] c) throws Plugboard.PlugAlreadyUsedException
- {
- plugboard = new Plugboard();
- if (c != null)
- {
- //Set each plug pair
- for (char[] x : c)
- {
- plugboard.setPlugPair(x[0], x[1]);
- }
- }
- }
-
- /**
- * Set config of the enigma
- *
- * @param conf configuration
- */
- public void setConfiguration(int[] conf)
- {
- if (conf.length != 10)
- {
- setConfiguration(Enigma.STANDARD_CONFIGURATION);
- } else
- {
- int ro1 = conf[0];
- int ro2 = conf[1];
- int ro3 = conf[2];
- int ref = conf[3];
- int r1rot = 26 + conf[4] - 1;
- int r2rot = 26 + conf[5] - 1;
- int r3rot = 26 + conf[6] - 1;
- int ro1Ring = conf[7];
- int ro2Ring = conf[8];
- int ro3Ring = conf[9];
-
- //Set first rotor
- switch (ro1)
- {
- case 1:
- {
- r1 = new Rotor('1', (r1rot) % 26, ro1Ring);
- break;
- }
- case 2:
- {
- r1 = new Rotor('2', (r1rot) % 26, ro1Ring);
- break;
- }
- case 3:
- {
- r1 = new Rotor('3', (r1rot) % 26, ro1Ring);
- break;
- }
- case 4:
- {
- r1 = new Rotor('4', (r1rot) % 26, ro1Ring);
- break;
- }
- case 5:
- {
- r1 = new Rotor('5', (r1rot) % 26, ro1Ring);
- break;
- }
- }
- //Set second rotor
- switch (ro2)
- {
- case 1:
- {
- r2 = new Rotor('1', (r2rot) % 26, ro2Ring);
- break;
- }
- case 2:
- {
- r2 = new Rotor('2', (r2rot) % 26, ro2Ring);
- break;
- }
- case 3:
- {
- r2 = new Rotor('3', (r2rot) % 26, ro2Ring);
- break;
- }
- case 4:
- {
- r2 = new Rotor('4', (r2rot) % 26, ro2Ring);
- break;
- }
- case 5:
- {
- r2 = new Rotor('5', (r2rot) % 26, ro2Ring);
- break;
- }
- }
- //Set third rotor
- switch (ro3)
- {
- case 1:
- {
- r3 = new Rotor('1', (r3rot) % 26, ro3Ring);
- break;
- }
- case 2:
- {
- r3 = new Rotor('2', (r3rot) % 26, ro3Ring);
- break;
- }
- case 3:
- {
- r3 = new Rotor('3', (r3rot) % 26, ro3Ring);
- break;
- }
- case 4:
- {
- r3 = new Rotor('4', (r3rot) % 26, ro3Ring);
- break;
- }
- case 5:
- {
- r3 = new Rotor('5', (r3rot) % 26, ro3Ring);
- break;
- }
- }
- //Set reflector
- switch (ref)
- {
- case 1:
- {
- reflector = new Rotor('A', 0, 0);
- break;
- }
- case 2:
- {
- reflector = new Rotor('B', 0, 0);
- break;
- }
- case 3:
- {
- reflector = new Rotor('C', 0, 0);
- break;
- }
- }
- }
- }
-
- /**
- * Return the configuration, the enigma machine is in right NOW
- *
- * @return array containing configuration
- */
- public int[] getConfiguration()
- {
- int[] c = new int[10];
- {
- c[0] = r1.getType();
- c[1] = r2.getType();
- c[2] = r3.getType();
- c[3] = reflector.getType();
- c[4] = r1.getCounter();
- c[5] = r2.getCounter();
- c[6] = r3.getCounter();
- c[7] = r1.getRingsetting();
- c[8] = r2.getRingsetting();
- c[9] = r3.getRingsetting();
- }
- return c;
- }
-
- public void setPrefAnomaly(boolean b)
- {
- this.prefAnomaly = b;
- }
-
- public static class InvalidPlugboardConfigurationFormatException extends Exception
- {
- public InvalidPlugboardConfigurationFormatException(String m)
- {
- super(m);
- }
- }
-}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/MainActivity.java b/app/src/main/java/de/vanitasvitae/enigmandroid/MainActivity.java
index 04f61c7..363be73 100644
--- a/app/src/main/java/de/vanitasvitae/enigmandroid/MainActivity.java
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/MainActivity.java
@@ -1,357 +1,509 @@
/**
- * Copyright (C) 2015 Paul Schaub
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
*/
-
package de.vanitasvitae.enigmandroid;
import android.app.Activity;
import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.ClipData;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
-import android.view.View;
+import android.text.InputType;
+import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.View;
+import android.widget.Button;
import android.widget.EditText;
-import android.widget.Spinner;
-import android.widget.ArrayAdapter;
+import android.widget.LinearLayout;
+import android.widget.TextView;
import android.widget.Toast;
+import com.google.zxing.integration.android.IntentIntegrator;
+import com.google.zxing.integration.android.IntentResult;
+
+import java.math.BigInteger;
+import java.security.SecureRandom;
+
+import de.vanitasvitae.enigmandroid.enigma.Enigma;
+import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
+import de.vanitasvitae.enigmandroid.enigma.inputPreparer.InputPreparer;
+import de.vanitasvitae.enigmandroid.layout.LayoutContainer;
+import de.vanitasvitae.enigmandroid.layout.PassphraseDialogBuilder;
+
public class MainActivity extends Activity
{
- private Spinner rotor1;
- private Spinner rotor2;
- private Spinner rotor3;
- private Spinner reversingRotor;
- private Spinner rotor1Position;
- private Spinner rotor2Position;
- private Spinner rotor3Position;
- private EditText plugboard;
- private EditText input;
- private EditText output;
+ private static final int RESULT_SETTINGS = 1;
+ private static final String URI_CHANGELOG =
+ "https://github.com/vanitasvitae/EnigmAndroid/blob/master/CHANGELOG.txt";
+ public static final String APP_ID = "EnigmAndroid";
+ public static final int latest_protocol_version = 1;
+ public static final int max_protocol_version = 256;
- private static final int RESULT_SETTINGS = 1;
- private static final String URI_CHANGELOG = "https://github.com/vanitasvitae/EnigmAndroid/blob/master/CHANGELOG.txt";
+ private LayoutContainer layoutContainer;
- private Enigma enigma;
- //memory for the ringsettings
- private int[] ringsettings = {0,0,0};
- private boolean anomaly = true;
+ private SecureRandom secureRandom;
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- this.setContentView(R.layout.activity_main);
- this.initLayout();
- this.reset();
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ secureRandom = new SecureRandom();
+ ActivitySingleton.getInstance().setActivity(this);
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
+ SettingsActivity.SettingsSingleton.getInstance(prefs, getResources());
+ layoutContainer = LayoutContainer.createLayoutContainer();
- }
+ //Handle shared text
+ Intent intent = getIntent();
+ String action = intent.getAction();
+ String type = intent.getType();
+ if (Intent.ACTION_SEND.equals(action) && type != null) {
+ if ("text/plain".equals(type))
+ {
+ String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
+ if (sharedText != null)
+ {
+ //If shared text consists of an encoded configuration, try to restore it
+ if(sharedText.startsWith(APP_ID+"/"))
+ restoreStateFromCode(sharedText);
+ //Else put it in the input text box
+ else
+ layoutContainer.getInput().setRawText(sharedText);
+ }
+ }
+ }
+ }
- @Override
- public boolean onCreateOptionsMenu(Menu menu)
- {
- this.getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
+ public SecureRandom getSecureRandom()
+ {
+ return this.secureRandom;
+ }
- @Override
- /**
- * Handle Options menu clicks
- */
- public boolean onOptionsItemSelected(MenuItem item)
- {
- int id = item.getItemId();
- if (id == R.id.action_reset)
- {
- this.reset();
- Toast.makeText(getApplicationContext(), R.string.message_reset,
- Toast.LENGTH_SHORT).show();
- return true;
- }
- else if (id == R.id.action_choose_ringstellung)
- {
- showRingsettingsDialog();
- return true;
- }
- else if (id == R.id.action_settings)
- {
- Intent i = new Intent(this, SettingsActivity.class);
- startActivityForResult(i, RESULT_SETTINGS);
- }
- else if (id == R.id.action_about)
- {
- showAboutDialog();
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
+ public void onDialogFinished(EnigmaStateBundle state)
+ {
+ layoutContainer.getEnigma().setState(state);
+ }
- /**
- * Updates the enigma to the chosen rotors and plugboard
- *
- * @param v View
- */
- public void updateEnigma(View v)
- {
- int[] conf = new int[10];
- conf[0] = rotor1.getSelectedItemPosition() + 1;
- conf[1] = rotor2.getSelectedItemPosition() + 1;
- conf[2] = rotor3.getSelectedItemPosition() + 1;
- conf[3] = reversingRotor.getSelectedItemPosition() + 1;
- conf[4] = rotor1Position.getSelectedItemPosition() + 1;
- conf[5] = rotor2Position.getSelectedItemPosition() + 1;
- conf[6] = rotor3Position.getSelectedItemPosition() + 1;
- conf[7] = ringsettings[0];
- conf[8] = ringsettings[1];
- conf[9] = ringsettings[2];
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu)
+ {
+ this.getMenuInflater().inflate(R.menu.main, menu);
+ return true;
+ }
- try
- {
- enigma = new Enigma(null, null);
- } catch (Plugboard.PlugAlreadyUsedException e)
- {
- //There is nothing that could possibly go wrong here.
- }
+ @Override
+ /**
+ * Handle Options menu clicks
+ */
+ public boolean onOptionsItemSelected(MenuItem item)
+ {
+ int id = item.getItemId();
+ if (id == R.id.action_reset)
+ {
+ layoutContainer.resetLayout();
+ Toast.makeText(getApplicationContext(), R.string.message_reset,
+ Toast.LENGTH_SHORT).show();
+ return true;
+ }
+ else if (id == R.id.action_send_message)
+ {
+ if(layoutContainer.getOutput().getText().length() == 0)
+ {
+ Toast.makeText(this, R.string.error_no_text_to_send, Toast.LENGTH_SHORT).show();
+ }
+ else
+ {
+ Intent sendIntent = new Intent();
+ sendIntent.setAction(Intent.ACTION_SEND);
+ sendIntent.putExtra(Intent.EXTRA_TEXT, layoutContainer.getOutput().getModifiedText());
+ sendIntent.setType("text/plain");
+ startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
+ }
+ }
+ else if (id == R.id.action_choose_ringsetting)
+ {
+ layoutContainer.showRingSettingsDialog();
+ return true;
+ }
+ else if(id == R.id.action_share_configuration)
+ {
+ showShareConfigurationDialog();
+ }
+ else if (id == R.id.action_restore_configuration)
+ {
+ showReceiveConfigurationDialog();
+ return true;
+ }
+ else if (id == R.id.action_random_configuration)
+ {
+ layoutContainer.getEnigma().randomState();
+ layoutContainer.syncStateFromEnigmaToLayout();
+ Toast.makeText(getApplicationContext(), R.string.message_random,
+ Toast.LENGTH_SHORT).show();
+ layoutContainer.getOutput().setText("");
+ return true;
+ }
+ else if (id == R.id.action_settings)
+ {
+ Intent i = new Intent(this, SettingsActivity.class);
+ startActivityForResult(i, RESULT_SETTINGS);
+ }
+ else if (id == R.id.action_about)
+ {
+ showAboutDialog();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
- char[][] plugboardConfiguration = null;
- try
- {
- plugboardConfiguration = Enigma.parsePlugs(plugboard.getText().toString());
- } catch (Enigma.InvalidPlugboardConfigurationFormatException e)
- {
- String error = this.getResources().getString(R.string.error_parsing_plugs) + ": " + e.getMessage();
- Toast.makeText(getApplicationContext(), error,
- Toast.LENGTH_LONG).show();
- }
- try
- {
- enigma.setConfiguration(conf);
- enigma.setPlugboard(plugboardConfiguration);
- enigma.setPrefAnomaly(anomaly);
+ /**
+ * Set the chosen Configuration to the enigma, get the input string from the input text box and
+ * prepare it, set the input to the prepared text, encrypt the prepared input and set the
+ * encrypted string to the output text box and update the spinners to their new positions.
+ * @param v View
+ */
+ public void doCrypto(View v)
+ {
+ layoutContainer.doCrypto();
+ }
- } catch (Plugboard.PlugAlreadyUsedException e)
- {
- Toast.makeText(this.getApplicationContext(), e.getMessage(),
- Toast.LENGTH_LONG).show();
- }
- }
+ /**
+ * Start an intent to share the configuration as QR-Code via Barcode Scanner
+ */
+ private void shareConfigurationAsQR()
+ {
+ IntentIntegrator QRIntegrator = new IntentIntegrator(this);
+ layoutContainer.syncStateFromLayoutToEnigma();
+ String encoded_state = APP_ID+"/"+layoutContainer.getEnigma().getEncodedState().toString(16);
+ Log.d(APP_ID, "Sharing configuration to QR: "+encoded_state);
+ QRIntegrator.shareText(encoded_state);
+ }
- /**
- * Set the chosen Configuration to the enigma, get the input string from the input textbox and prepare it,
- * set the input to the prepared text, encrypt the prepared input and set the encrypted string to the
- * output textbox and update the spinners to their new positions.
- * @param v View
- */
- public void doCrypto(View v)
- {
- updateEnigma(null);
- String m = input.getText().toString();
- m = Enigma.prepare(m);
- input.setText(m);
- output.setText(enigma.encrypt(m));
- updateSpinner(enigma.getConfiguration());
+ /**
+ * Start an intent to share the configuration as text
+ */
+ private void shareConfigurationAsText()
+ {
+ Intent sendIntent = new Intent();
+ sendIntent.setAction(Intent.ACTION_SEND);
+ sendIntent.putExtra(Intent.EXTRA_TEXT,
+ APP_ID+"/"+layoutContainer.getEnigma().getEncodedState().toString(16));
+ sendIntent.setType("text/plain");
+ startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
+ }
- }
+ /**
+ * Start the barcode app to scan a barcode for configuration
+ */
+ private void receiveConfigurationQR()
+ {
+ IntentIntegrator integrator = new IntentIntegrator(this);
+ integrator.initiateScan();
+ }
+ /**
+ * Show a dialog to restore a configuration
+ */
+ private void receiveConfigurationText()
+ {
+ new PassphraseDialogBuilder().showDialog();
+ }
- /**
- * Reset all the spinners and textboxes and the ringsettings memory
- */
- private void reset()
- {
- rotor1.setSelection(0);
- rotor2.setSelection(1);
- rotor3.setSelection(2);
- reversingRotor.setSelection(1);
- rotor1Position.setSelection(0);
- rotor2Position.setSelection(0);
- rotor3Position.setSelection(0);
- ringsettings = new int[]{0,0,0};
- plugboard.setText("");
- input.setText("");
- output.setText("");
- }
+ /**
+ * Show a Dialog containing information about the app, license, usage, author and a link
+ * to the changelog
+ */
+ private void showAboutDialog()
+ {
+ final View aboutView = View.inflate(this, R.layout.dialog_about, null);
+ //Get and set Version code
+ PackageInfo pInfo = null;
+ try{ pInfo = getPackageManager().getPackageInfo(this.getPackageName(), 0);}
+ catch (PackageManager.NameNotFoundException e){ e.printStackTrace();}
+ assert pInfo != null;
+ String version = pInfo.versionName+ " ("+pInfo.versionCode+")";
+ TextView versionText = (TextView) aboutView.findViewById(R.id.about_version_section);
+ versionText.setText(version);
- /**
- * Initialize the Layout
- */
- private void initLayout()
- {
- rotor1 = (Spinner) findViewById(R.id.rotor1);
- ArrayAdapter rotor1Adapter = ArrayAdapter.createFromResource(this,
- R.array.enigma_rotors, android.R.layout.simple_spinner_item);
- rotor1Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- rotor1.setAdapter(rotor1Adapter);
+ //Build and show dialog
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.title_about_dialog);
+ builder.setView(aboutView)
+ .setCancelable(true)
+ .setPositiveButton(R.string.dialog_positive, new DialogInterface.OnClickListener()
+ {
+ public void onClick(DialogInterface dialog, int id)
+ {
+ dialog.dismiss();
+ }
+ })
+ .setNegativeButton(R.string.button_show_changelog, new DialogInterface.OnClickListener()
+ {
+ public void onClick(DialogInterface dialog, int id)
+ {
+ dialog.cancel();
+ openWebPage(URI_CHANGELOG);
+ }
+ }).show();
+ }
+ /**
+ * Show a dialog where the user can choose between sharing the configuration via QR-code or
+ * via string (intent or copy-to-clipboard)
+ */
+ private void showShareConfigurationDialog()
+ {
+ final String configuration = APP_ID+"/"+layoutContainer.getEnigma().getEncodedState().toString(16);
+ final View shareView = View.inflate(this, R.layout.dialog_two_options, null);
+ LinearLayout l = (LinearLayout) shareView.findViewById(R.id.dialog_two_options_lay);
+ EditText e = new EditText(this);
+ e.setText(configuration);
+ e.setInputType(InputType.TYPE_NULL);
+ e.setOnClickListener(new View.OnClickListener()
+ {
+ @Override
+ public void onClick(View v)
+ {
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB){
+ android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
+ ClipData clip;
+ clip = ClipData.newPlainText("label", configuration);
+ clipboard.setPrimaryClip(clip);
+ } else{
+ @SuppressWarnings("deprecation")
+ android.text.ClipboardManager clipboard = (android.text.ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
+ clipboard.setText(configuration);
+ }
+ Toast.makeText(getApplicationContext(), R.string.message_clipboard, Toast.LENGTH_SHORT).show();
+ }
+ });
+ l.addView(e);
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.dialog_title_share_configuration)
+ .setView(shareView).setCancelable(true);
+ final Dialog d = builder.create();
+ Button one = (Button) shareView.findViewById(R.id.dialog_two_options_1);
+ one.setText(R.string.dialog_share_qr);
+ one.setOnClickListener(new View.OnClickListener()
+ {
+ @Override
+ public void onClick(View v)
+ {
+ shareConfigurationAsQR();
+ d.dismiss();
+ }
+ });
+ Button two = (Button) shareView.findViewById(R.id.dialog_two_options_2);
+ two.setText(R.string.dialog_share_code);
+ two.setOnClickListener(new View.OnClickListener()
+ {
+ @Override
+ public void onClick(View v)
+ {
+ shareConfigurationAsText();
+ d.dismiss();
+ }
+ });
+ d.show();
+ }
- rotor2 = (Spinner) findViewById(R.id.rotor2);
- ArrayAdapter rotor2Adapter = ArrayAdapter.createFromResource(this,
- R.array.enigma_rotors, android.R.layout.simple_spinner_item);
- rotor2Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- rotor2.setAdapter(rotor2Adapter);
+ /**
+ * Show a dialog, where the user can choose between scanning QR-code and entering a string to
+ * restore the encoded configuration
+ */
+ private void showReceiveConfigurationDialog()
+ {
+ final View shareView = View.inflate(this, R.layout.dialog_two_options, null);
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.dialog_title_restore_configuration)
+ .setView(shareView).setCancelable(true);
+ final Dialog d = builder.create();
+ Button one = (Button) shareView.findViewById(R.id.dialog_two_options_1);
+ one.setText(R.string.dialog_restore_qr);
+ one.setOnClickListener(new View.OnClickListener()
+ {
+ @Override
+ public void onClick(View v)
+ {
+ receiveConfigurationQR();
+ d.dismiss();
+ }
+ });
+ Button two = (Button) shareView.findViewById(R.id.dialog_two_options_2);
+ two.setText(R.string.dialog_restore_code);
+ two.setOnClickListener(new View.OnClickListener()
+ {
+ @Override
+ public void onClick(View v)
+ {
+ receiveConfigurationText();
+ d.dismiss();
+ }
+ });
+ d.show();
+ }
- rotor3 = (Spinner) findViewById(R.id.rotor3);
- ArrayAdapter rotor3Adapter = ArrayAdapter.createFromResource(this,
- R.array.enigma_rotors, android.R.layout.simple_spinner_item);
- rotor3Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- rotor3.setAdapter(rotor3Adapter);
+ /**
+ * Handle Activity Results
+ * @param requestCode requestCode
+ * @param resultCode resultCode (RESULT_SETTINGS is defined at the top)
+ * @param data data
+ */
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ switch (requestCode) {
+ //Come back from Settings
+ case RESULT_SETTINGS:
+ {
+ applyPreferenceChanges();
+ break;
+ }
+ // Receive from QR
+ case IntentIntegrator.REQUEST_CODE:
+ IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
+ if (scanResult != null) {
+ String content = scanResult.getContents();
+ if(content == null) Log.e(APP_ID, "Error! Received nothing from QR-Code!");
+ else {
+ Log.d(APP_ID, "Received " + content + " from QR-Code!");
+ restoreStateFromCode(content);
+ }
+ }
+ }
+ }
- reversingRotor = (Spinner) findViewById(R.id.reflector);
- ArrayAdapter relfectorAdapter = ArrayAdapter.createFromResource(this,
- R.array.enigma_reflectors, android.R.layout.simple_spinner_item);
- relfectorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- reversingRotor.setAdapter(relfectorAdapter);
+ /**
+ * Handle changes in preferences and apply those changes to the app
+ */
+ private void applyPreferenceChanges()
+ {
+ SettingsActivity s = SettingsActivity.SettingsSingleton.getInstance();
+ if(s.prefMachineTypeChanged())
+ {
+ layoutContainer = LayoutContainer.createLayoutContainer();
+ }
+ if(s.prefMessageFormattingChanged())
+ {
+ layoutContainer.setEditTextAdapter(s.getPrefMessageFormatting());
+ }
+ if(s.prefNumericLanguageChanged())
+ {
+ layoutContainer.setInputPreparer(InputPreparer.createInputPreparer());
+ }
+ }
- rotor1Position = (Spinner) findViewById(R.id.rotor1position);
- ArrayAdapter rotor1PositionAdapter = ArrayAdapter.createFromResource(this,
- R.array.rotor_positions, android.R.layout.simple_spinner_item);
- rotor1PositionAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- rotor1Position.setAdapter(rotor1PositionAdapter);
+ /**
+ * Set EnigmAndroid into a certain state as described in the QR-Code
+ * @param mem content of the QR-Code
+ */
+ public void restoreStateFromCode(String mem)
+ {
+ if(!mem.startsWith(APP_ID+"/"))
+ {
+ Toast.makeText(this, R.string.error_no_valid_qr, Toast.LENGTH_LONG).show();
+ }
+ else
+ {
+ String inputString = layoutContainer.getInput().getText();
+ mem = mem.substring((APP_ID+"/").length());
+ BigInteger s = new BigInteger(mem, 16);
+ int protocol_version = Enigma.getValue(s, max_protocol_version);
+ s = Enigma.removeDigit(s, max_protocol_version);
+ Log.d(APP_ID,
+ "Try to restore configuration from BigInteger value "+s.toString()+" in protocol version "+protocol_version+".");
+ SettingsActivity.SettingsSingleton.getInstance()
+ .setPrefMachineType(Enigma.chooseEnigmaFromSave(s));
+ layoutContainer = LayoutContainer.createLayoutContainer();
+ layoutContainer.getEnigma().restoreState(Enigma.removeDigit(s,20), protocol_version);
+ layoutContainer.setInputPreparer(InputPreparer.createInputPreparer());
+ layoutContainer.syncStateFromEnigmaToLayout();
+ layoutContainer.getInput().setText(inputString);
+ layoutContainer.getOutput().setText("");
+ }
+ }
- rotor2Position = (Spinner) findViewById(R.id.rotor2position);
- ArrayAdapter rotor2PositionAdapter = ArrayAdapter.createFromResource(this,
- R.array.rotor_positions, android.R.layout.simple_spinner_item);
- rotor2PositionAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- rotor2Position.setAdapter(rotor2PositionAdapter);
+ /**
+ * Set EnigmAndroid into a state calculated from the seed.
+ * @param seed seed
+ */
+ public void applyStateFromSeed(String seed)
+ {
+ String inputString = layoutContainer.getInput().getText();
+ SettingsActivity.SettingsSingleton.getInstance()
+ .setPrefMachineType(Enigma.chooseEnigmaFromSeed(seed));
+ layoutContainer = LayoutContainer.createLayoutContainer();
+ layoutContainer.getEnigma().setStateFromSeed(seed);
+ layoutContainer.setInputPreparer(InputPreparer.createInputPreparer());
+ layoutContainer.syncStateFromEnigmaToLayout();
+ layoutContainer.getInput().setText(inputString);
+ layoutContainer.getOutput().setText("");
+ }
- rotor3Position = (Spinner) findViewById(R.id.rotor3position);
- ArrayAdapter rotor3PositionAdapter = ArrayAdapter.createFromResource(this,
- R.array.rotor_positions, android.R.layout.simple_spinner_item);
- rotor3PositionAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- rotor3Position.setAdapter(rotor3PositionAdapter);
+ /**
+ * Open the web page with the URL url
+ * @param url URL of the website
+ */
+ private void openWebPage(String url) {
+ Uri webPage = Uri.parse(url);
+ Intent intent = new Intent(Intent.ACTION_VIEW, webPage);
+ if (intent.resolveActivity(getPackageManager()) != null) {
+ startActivity(intent);
+ }
+ }
- plugboard = (EditText) findViewById(R.id.plugboard);
- input = (EditText) findViewById(R.id.input);
- output = (EditText) findViewById(R.id.output);
+ /**
+ * Singleton that grants access to an Activity from anywhere within the app
+ */
+ public static class ActivitySingleton
+ {
+ private static ActivitySingleton instance = null;
+ private Activity activity;
- input.requestFocus();
- }
+ //private constructor
+ private ActivitySingleton(){}
+ //Singleton method
+ public static ActivitySingleton getInstance()
+ {
+ if(instance == null) instance = new ActivitySingleton();
+ return instance;
+ }
- /**
- * Update the Spinners to their new Positions
- * @param c Configuration
- */
- public void updateSpinner(int[] c)
- {
- rotor1.setSelection(c[0] - 1);
- rotor2.setSelection(c[1] - 1);
- rotor3.setSelection(c[2] - 1);
- rotor1Position.setSelection(c[4]);
- rotor2Position.setSelection(c[5]);
- rotor3Position.setSelection(c[6]);
- }
+ /**
+ * Set an Activity that the Singleton returns
+ * @param activity activity that's stored
+ */
+ public void setActivity(Activity activity)
+ {
+ this.activity = activity;
+ }
- /**
- * Show the dialog where the user can pick the ringsettings and set them if the user doesn't abort.
- */
- public void showRingsettingsDialog()
- {
- View ringsettingsView = View.inflate(this, R.layout.dialog_ringsettings, null);
+ /**
+ * Returns the stored Activity
+ * @return stored Activity
+ */
+ public Activity getActivity()
+ {
+ return activity;
+ }
- final Spinner ring1 = (Spinner) ringsettingsView.findViewById(R.id.rotor1ring);
- ArrayAdapter ring1Adapter = ArrayAdapter.createFromResource(this, R.array.ring_positions, android.R.layout.simple_spinner_item);
- ring1Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- ring1.setAdapter(ring1Adapter);
- ring1.setSelection(ringsettings[0]);
-
- final Spinner ring2 = (Spinner) ringsettingsView.findViewById(R.id.rotor2ring);
- ArrayAdapter ring2Adapter = ArrayAdapter.createFromResource(this, R.array.ring_positions, android.R.layout.simple_spinner_item);
- ring2Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- ring2.setAdapter(ring2Adapter);
- ring2.setSelection(ringsettings[1]);
-
- final Spinner ring3 = (Spinner) ringsettingsView.findViewById(R.id.rotor3ring);
- ArrayAdapter ring3Adapter = ArrayAdapter.createFromResource(this, R.array.ring_positions, android.R.layout.simple_spinner_item);
- ring3Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- ring3.setAdapter(ring3Adapter);
- ring3.setSelection(ringsettings[2]);
-
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle(R.string.title_ringsetting);
- builder.setView(ringsettingsView)
- .setCancelable(true)
- .setPositiveButton(R.string.dialog_positiv, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int id)
- {
- ringsettings = new int[]{ring1.getSelectedItemPosition(), ring2.getSelectedItemPosition(), ring3.getSelectedItemPosition()};
- String message = getResources().getString(R.string.dialog_ringsettings_success) + " " + (ringsettings[2]+1) + ", " + (ringsettings[1]+1) + ", " + (ringsettings[0]+1) + ".";
- Toast.makeText(getApplicationContext(), message,
- Toast.LENGTH_LONG).show();
- }
- })
- .setNegativeButton(R.string.dialog_negativ, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int id)
- {
- dialog.cancel();
- Toast.makeText(getApplicationContext(), R.string.dialog_ringsettings_abort,
- Toast.LENGTH_SHORT).show();
- }
- }).show();
- }
-
- public void showAboutDialog()
- {
- final View aboutView = View.inflate(this, R.layout.dialog_about, null);
-
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle(R.string.title_about_dialog);
- builder.setView(aboutView)
- .setCancelable(true)
- .setPositiveButton(R.string.dialog_positiv, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int id)
- {
- dialog.dismiss();
- }
- })
- .setNegativeButton(R.string.button_show_changelog, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int id)
- {
- dialog.cancel();
- openWebPage(URI_CHANGELOG);
- }
- }).show();
- }
-
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
-
- switch (requestCode) {
- case RESULT_SETTINGS:
- {
- SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
- this.anomaly = sharedPrefs.getBoolean("prefAnomaly", true);
- break;
- }
- }
- }
-
- public void openWebPage(String url) {
- Uri webpage = Uri.parse(url);
- Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
- if (intent.resolveActivity(getPackageManager()) != null) {
- startActivity(intent);
- }
- }
+ }
}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/Plugboard.java b/app/src/main/java/de/vanitasvitae/enigmandroid/Plugboard.java
deleted file mode 100644
index 709a581..0000000
--- a/app/src/main/java/de/vanitasvitae/enigmandroid/Plugboard.java
+++ /dev/null
@@ -1,102 +0,0 @@
-package de.vanitasvitae.enigmandroid;
-
-/**
- * Class representing the plugboard
- *Copyright (C) 2015 Paul Schaub
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- * @author vanitasvitae
- */
-public class Plugboard
-{
- //Plugboard
- // Q W E R T Z U I O
- // A S D F G H J K
- // P Y X C V B N M L
-
- //Array containing plugged pairs
- int[] pb;
- //Standard array to compare pb to.
- public static final int[] ref = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25};
-
- /**
- * Create new plugboard without any plugged pairs. (empty, no scrambling here)
- */
- public Plugboard()
- {
- pb = new int[26];
- resetPlugboard();
- }
-
- /**
- * En-/decrypt a char following the connections on the plugboard
- *
- * @param x char to perform crypto on
- * @return en-/decrypted char
- */
- public int encrypt(int x)
- {
- return pb[x];
- }
-
- /**
- * Reset the plugboard (no plugged pairs)
- */
- public void resetPlugboard()
- {
- pb = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25};
- }
-
- /**
- * Set a pair of plugs on the plugboard
- *
- * @param a first Plug
- * @param b second Plug
- */
- public void setPlugPair(char a, char b) throws PlugAlreadyUsedException
- {
- //prevent to plug a plug to itself
- if (a == b)
- {
- throw new PlugAlreadyUsedException("Unable to plug " + a + " to " + a);
- }
- int x = a - 65;
- int y = b - 65;
- //Check, if plugs already plugged
- if (pb[x] != ref[x])
- {
- throw new PlugAlreadyUsedException("Plug " + a + " used twice!");
- } else if (pb[y] != ref[y])
- {
- throw new PlugAlreadyUsedException("Plug " + b + " used twice!");
- }
- //If everything is correct
- else
- {
- //set the pair
- int c = pb[x];
- pb[x] = pb[y];
- pb[y] = c;
- }
- }
-
- public static class PlugAlreadyUsedException extends Exception
- {
- public PlugAlreadyUsedException(String m)
- {
- super(m);
- }
- }
-}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/Rotor.java b/app/src/main/java/de/vanitasvitae/enigmandroid/Rotor.java
deleted file mode 100644
index f7cd92b..0000000
--- a/app/src/main/java/de/vanitasvitae/enigmandroid/Rotor.java
+++ /dev/null
@@ -1,256 +0,0 @@
-package de.vanitasvitae.enigmandroid;
-
-/**
- * Class representing a rotor of the Enigma machine (I-V,A-C)
- *Copyright (C) 2015 Paul Schaub
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- * @author vanitas
- */
-public class Rotor
-{
- // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
- //ABC: 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
- //Rotor1: 'E','K','M','F','L','G','D','Q','V','Z','N','T','O','W','Y','H','X','U','S','P','A','I','B','R','C','J'
- //Rotor2: 'A','J','D','K','S','I','R','U','X','B','L','H','W','T','M','C','Q','G','Z','N','P','Y','F','V','O','E'
- //Rotor3: 'B','D','F','H','J','L','C','P','R','T','X','V','Z','N','Y','E','I','W','G','A','K','M','U','S','Q','O'
- //Rotor4: 'E','S','O','V','P','Z','J','A','Y','Q','U','I','R','H','X','L','N','F','T','G','K','D','C','M','W','B'
- //Rotor5: 'V','Z','B','R','G','I','T','Y','U','P','S','D','N','H','L','X','A','W','M','J','Q','O','F','E','C','K'
- //Reversing Rotor A: AE BJ CM DZ FL GY HX IV KW NR OQ PU ST
- //Reversing Rotor B: AY BR CU DH EQ FS GL IP JX KN MO TZ VW
- //Reversing Rotor C: AF BV CP DJ EI GO HY KR LZ MX NW QT SU
-
- //Original rotors
- public static final Integer[] rotor1 = {4, 10, 12, 5, 11, 6, 3, 16, 21, 25, 13, 19, 14, 22, 24, 7, 23, 20, 18, 15, 0, 8, 1, 17, 2, 9};
- public static final Integer[] rotor2 = {0, 9, 3, 10, 18, 8, 17, 20, 23, 1, 11, 7, 22, 19, 12, 2, 16, 6, 25, 13, 15, 24, 5, 21, 14, 4};
- public static final Integer[] rotor3 = {1, 3, 5, 7, 9, 11, 2, 15, 17, 19, 23, 21, 25, 13, 24, 4, 8, 22, 6, 0, 10, 12, 20, 18, 16, 14};
- public static final Integer[] rotor4 = {4, 18, 14, 21, 15, 25, 9, 0, 24, 16, 20, 8, 17, 7, 23, 11, 13, 5, 19, 6, 10, 3, 2, 12, 22, 1};
- public static final Integer[] rotor5 = {21, 25, 1, 17, 6, 8, 19, 24, 20, 15, 18, 3, 13, 7, 11, 23, 0, 22, 12, 9, 16, 14, 5, 4, 2, 10};
- //Original rotors backwards direction
- public static final Integer[] backwardsRotor1 = {20, 22, 24, 6, 0, 3, 5, 15, 21, 25, 1, 4, 2, 10, 12, 19, 7, 23, 18, 11, 17, 8, 13, 16, 14, 9};
- public static final Integer[] backwardsRotor2 = {0, 9, 15, 2, 25, 22, 17, 11, 5, 1, 3, 10, 14, 19, 24, 20, 16, 6, 4, 13, 7, 23, 12, 8, 21, 18};
- public static final Integer[] backwardsRotor3 = {19, 0, 6, 1, 15, 2, 18, 3, 16, 4, 20, 5, 21, 13, 25, 7, 24, 8, 23, 9, 22, 11, 17, 10, 14, 12};
- public static final Integer[] backwardsRotor4 = {7, 25, 22, 21, 0, 17, 19, 13, 11, 6, 20, 15, 23, 16, 2, 4, 9, 12, 1, 18, 10, 3, 24, 14, 8, 5};
- public static final Integer[] backwardsRotor5 = {16, 2, 24, 11, 23, 22, 4, 13, 5, 19, 25, 14, 18, 12, 21, 9, 20, 3, 10, 6, 8, 0, 17, 15, 7, 1};
-
- //Original reflector rotors A,B,C, D, E,F, G, H, I, J,K, L,M,N, O, P, Q, R, S, T, U, V,W, X,Y,Z
- public static final Integer[] reflectorA = {4, 9, 12, 25, 0, 11, 24, 23, 21, 1, 22, 5, 2, 17, 16, 20, 14, 13, 19, 18, 15, 8, 10, 7, 6, 3};
- public static final Integer[] reflectorB = {24, 17, 20, 7, 16, 18, 11, 3, 15, 23, 13, 6, 14, 10, 12, 8, 4, 1, 5, 25, 2, 22, 21, 9, 0, 19};
- public static final Integer[] reflectorC = {5, 21, 15, 9, 8, 0, 14, 24, 4, 3, 17, 25, 23, 22, 6, 2, 19, 10, 20, 16, 18, 1, 13, 12, 7, 11};
-
- //Attributes of the rotor
- private Integer[] rotor; //choose one of rotor1-5
- private Integer[] backwardsRotor; //choose one of backwardsRotor1-5
- private int ringsetting;
- private int turnOver;
- private int counter;
- private String name;
- private int type;
-
- /**
- * Create new Rotor (1 - 5 = normal rotor, -1 - -3 = reversing rotor)
- *
- * @param type integer determines type
- * @param setting setting (rotation) of the rotor
- */
- public Rotor(char type, int setting, int ring)
- {
- this.ringsetting = ring;
- switch (type)
- {
- case '1':
- {
- this.rotor = rotor1;
- this.backwardsRotor = backwardsRotor1;
- this.counter = setting;
- this.name = "I";
- this.turnOver = 17; //"Royal"
- this.type = 1;
- break;
- }
- case '2':
- {
- this.rotor = rotor2;
- this.backwardsRotor = backwardsRotor2;
- this.counter = setting;
- this.name = "II";
- this.turnOver = 5; //"Flags"
- this.type = 2;
- break;
- }
- case '3':
- {
- this.rotor = rotor3;
- this.backwardsRotor = backwardsRotor3;
- this.counter = setting;
- this.name = "III";
- this.turnOver = 22; //"Wave"
- this.type = 3;
- break;
- }
- case '4':
- {
- this.rotor = rotor4;
- this.backwardsRotor = backwardsRotor4;
- this.counter = setting;
- this.name = "IV";
- this.turnOver = 10; //"Kings"
- this.type = 4;
- break;
- }
- case '5':
- {
- this.rotor = rotor5;
- this.backwardsRotor = backwardsRotor5;
- this.counter = setting;
- this.name = "V";
- this.turnOver = 0; //"Above"
- this.type = 5;
- break;
- }
- case 'A':
- {
- this.rotor = reflectorA;
- this.backwardsRotor = null;
- this.counter = 0;
- this.name = "A";
- this.type = 1;
- break;
- }
- case 'B':
- {
- this.rotor = reflectorB;
- this.backwardsRotor = null;
- this.counter = 0;
- this.name = "B";
- this.type = 2;
- break;
- }
- case 'C':
- {
- this.rotor = reflectorC;
- this.backwardsRotor = null;
- this.counter = 0;
- this.name = "C";
- this.type = 3;
- break;
- }
- }
- }
-
- /**
- * encrypt in forward direction (forward means first half of the cycle through the rotors)
- *
- * @param x incoming character
- * @return encrypted character
- */
- public int encryptForward(int x)
- {
- return this.rotor[(26 + x) % 26];
- }
-
- /**
- * encrypt in backward direction (coming from the reversing rotor)
- *
- * @param x incoming character
- * @return encrypted character
- */
- public int encryptBackward(int x)
- {
- if (this.backwardsRotor == null) return this.rotor[(26 + x) % 26];
- else return this.backwardsRotor[(26 + x) % 26];
- }
-
- /**
- * return rotation of the rotor - the ringsetting
- *
- * @return rotation
- */
- public int getCounter()
- {
- return this.counter - this.getRingsetting();
- }
-
- /**
- * increment rotation of the rotor by one.
- */
- public void incrementCounter()
- {
- this.counter = (this.counter + 1) % 26;
- }
-
- /**
- * Return true, if rotor is at a position, where it turns over the next rotor
- *
- * @return boolean
- */
- public boolean isAtTurnoverPosition()
- {
- return this.counter == this.turnOver;
- }
-
- /**
- * The Double Turn Anomaly (deutsch: Doppelsprung Anomalie) is aa anomaly in the rotor movement caused by the mechanical implementation of the enigma.
- * Whenever the rightmost rotor turns the middle rotor AND the middle rotor is only one move from turning the leftmost rotor, the middle rotor turns again with the next character.
- * So technically there are only 26*25*26 possible rotor settings for any but firmly 3 rotors.
- *
- * @return boolean
- */
- public boolean doubleTurnAnomaly()
- {
- return this.counter == this.turnOver - 1;
- }
-
- @SuppressWarnings("unused")
- /**
- * Returns the position of the turnover notch
- *
- * @return turnOver
- */
- public int getTurnOver()
- {
- return this.turnOver;
- }
-
- @SuppressWarnings("unused")
- /**
- * Return the name of the rotor
- * @return name
- */
- public String getName()
- {
- return name;
- }
-
- @SuppressWarnings("unused")
- /**
- * Return ringsettings of the rotor
- * @return ringsetting
- */
- public int getRingsetting()
- {
- return this.ringsetting;
- }
-
- /**
- * Returns the integer, which was used to create this rotor.
- *
- * @return the type of the rotor
- */
- public int getType()
- {
- return this.type;
- }
-}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/SettingsActivity.java b/app/src/main/java/de/vanitasvitae/enigmandroid/SettingsActivity.java
index eaa4be6..4b36f3f 100644
--- a/app/src/main/java/de/vanitasvitae/enigmandroid/SettingsActivity.java
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/SettingsActivity.java
@@ -1,34 +1,254 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package de.vanitasvitae.enigmandroid;
+import android.content.SharedPreferences;
+import android.content.res.Resources;
import android.os.Bundle;
import android.preference.PreferenceActivity;
+import android.util.Log;
/**
* Class that represents the settings activity.
- * Copyright (C) 2015 Paul Schaub
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *@author vanitasvitae
+ * Use the singleton to get an instance of this class to get preferences
*/
public class SettingsActivity extends PreferenceActivity
{
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- //noinspection deprecation
- addPreferencesFromResource(R.xml.pref_page);
- }
-}
+ public static final String PREF_NUMERIC_LANGUAGE = "prefNumericLanguage";
+ public static final String PREF_MACHINE_TYPE = "prefMachineType";
+ public static final String PREF_MESSAGE_FORMATTING = "prefMessageFormatting";
+ public static final String PREF_REPLACE_SPECIAL_CHARACTERS = "prefReplaceSpecialCharacters";
+ public static final String PREF_SAVED_ENIGMA_STATE = "prefSavedEnigmaState";
+ public static final String PREF_VERSION_NUMBER = "prefVersionNumber";
+
+ private String previousPrefNumericLanguage;
+ private String previousPrefMachineType;
+ private String previousPrefMessageFormatting;
+ private boolean previousPrefReplaceSpecialCharacters;
+ private String previousPrefSavedEnigmaState;
+
+ private SharedPreferences prefs;
+ private Resources res;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ //noinspection deprecation
+ addPreferencesFromResource(R.xml.pref_page);
+ }
+
+ public void setSharedPreferences(SharedPreferences prefs)
+ {
+ this.prefs = prefs;
+ }
+
+ public void setResources(Resources res)
+ {
+ this.res = res;
+ }
+
+ private boolean isFullyInitialized()
+ {
+ if (prefs == null)
+ {
+ Log.e(MainActivity.APP_ID,
+ "SharedPreferences not initialized via setSharedPreferences!");
+ return false;
+ }
+ if (res == null)
+ {
+ Log.e(MainActivity.APP_ID, "Resources not initialized via setResources!");
+ return false;
+ }
+ return true;
+ }
+
+ public String getPrefNumericLanguage()
+ {
+ if (isFullyInitialized())
+ return prefs.getString(
+ PREF_NUMERIC_LANGUAGE,
+ res.getStringArray(R.array.pref_alias_message_formatting)[0]);
+ else return null;
+ }
+
+ public void setPrefNumericLanguage(String lang)
+ {
+ if (isFullyInitialized())
+ prefs.edit().putString(PREF_NUMERIC_LANGUAGE, lang).apply();
+ }
+
+ public boolean prefNumericLanguageChanged()
+ {
+ if (this.previousPrefNumericLanguage == null || !this.previousPrefNumericLanguage.equals(
+ getPrefNumericLanguage()))
+ {
+ this.previousPrefNumericLanguage = this.getPrefNumericLanguage();
+ Log.d(MainActivity.APP_ID, PREF_NUMERIC_LANGUAGE+" changed!");
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Return whether special characters will be replaced.
+ * If the SettingsActivity is not fully initialized return false and ignore preference.
+ * @return boolean
+ */
+ public boolean getPrefReplaceSpecialCharacters()
+ {
+ return isFullyInitialized() && prefs.getBoolean(PREF_REPLACE_SPECIAL_CHARACTERS, true);
+ }
+
+ public void setPrefReplaceSpecialCharacters(boolean replace)
+ {
+ if (isFullyInitialized())
+ prefs.edit().putBoolean(PREF_REPLACE_SPECIAL_CHARACTERS, replace).apply();
+ }
+
+ public boolean prefReplaceSpecialCharactersChanged()
+ {
+ boolean changed = previousPrefReplaceSpecialCharacters != getPrefReplaceSpecialCharacters();
+ if (changed)
+ {
+ previousPrefReplaceSpecialCharacters = getPrefReplaceSpecialCharacters();
+ Log.d(MainActivity.APP_ID, PREF_REPLACE_SPECIAL_CHARACTERS+" changed!");
+ return true;
+ }
+ return false;
+ }
+
+ public String getPrefMachineType()
+ {
+ if (isFullyInitialized())
+ return prefs.getString(PREF_MACHINE_TYPE,
+ res.getStringArray(R.array.pref_alias_machine_type)[0]);
+ else return null;
+ }
+
+ public void setPrefMachineType(String pref)
+ {
+ if (isFullyInitialized())
+ prefs.edit().putString(PREF_MACHINE_TYPE, pref).apply();
+ }
+
+ public boolean prefMachineTypeChanged()
+ {
+ if (this.previousPrefMachineType == null || !this.previousPrefMachineType.equals(
+ getPrefMachineType()))
+ {
+ this.previousPrefMachineType = this.getPrefMachineType();
+ Log.d(MainActivity.APP_ID, PREF_MACHINE_TYPE+" changed!");
+ return true;
+ }
+ return false;
+ }
+
+ public String getPrefSavedEnigmaState()
+ {
+ if (isFullyInitialized())
+ return prefs.getString(PREF_SAVED_ENIGMA_STATE, "-1");
+ else return null;
+ }
+
+ /**
+ * @param state HEX
+ */
+ public void setPrefSavedEnigmaState(String state)
+ {
+ if (isFullyInitialized())
+ prefs.edit().putString(PREF_SAVED_ENIGMA_STATE, state).apply();
+ }
+
+ public boolean prefSavedEnigmaStateChanged()
+ {
+ if (this.previousPrefSavedEnigmaState == null || !this.previousPrefSavedEnigmaState
+ .equals(getPrefSavedEnigmaState()))
+ {
+ this.previousPrefSavedEnigmaState = this.getPrefSavedEnigmaState();
+ Log.d(MainActivity.APP_ID, PREF_SAVED_ENIGMA_STATE+" changed!");
+ return true;
+ }
+ return false;
+ }
+
+ public String getPrefMessageFormatting()
+ {
+ if (isFullyInitialized())
+ return prefs.getString(SettingsActivity.PREF_MESSAGE_FORMATTING,
+ res.getStringArray(R.array.pref_alias_message_formatting)[0]);
+ else return null;
+ }
+
+ public void setPrefMessageFormatting(String format)
+ {
+ if (isFullyInitialized())
+ prefs.edit().putString(PREF_MESSAGE_FORMATTING, format).apply();
+ }
+
+ public boolean prefMessageFormattingChanged()
+ {
+ if (this.previousPrefMessageFormatting == null || !this.previousPrefMessageFormatting
+ .equals(getPrefMessageFormatting()))
+ {
+ this.previousPrefMessageFormatting = this.getPrefMessageFormatting();
+ Log.d(MainActivity.APP_ID, PREF_MESSAGE_FORMATTING+" changed!");
+ return true;
+ }
+ return false;
+ }
+
+ public int getVersionNumber()
+ {
+ if (isFullyInitialized())
+ return prefs.getInt(PREF_VERSION_NUMBER, -1);
+ else return -1;
+ }
+
+ public void setVersionNumber(int v)
+ {
+ if (isFullyInitialized())
+ prefs.edit().putInt(PREF_VERSION_NUMBER, v).apply();
+ }
+
+ public static class SettingsSingleton extends SettingsActivity
+ {
+ private static SettingsActivity instance;
+
+ private SettingsSingleton()
+ {
+ super();
+ }
+
+ public static SettingsActivity getInstance(SharedPreferences prefs, Resources res)
+ {
+ instance = new SettingsActivity();
+ instance.setSharedPreferences(prefs);
+ instance.setResources(res);
+ return instance;
+ }
+
+ public static SettingsActivity getInstance()
+ {
+ if (instance == null)
+ {
+ instance = new SettingsActivity();
+ Log.d(MainActivity.APP_ID, "Created new SettingsActivity!");
+ }
+ return instance;
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma.java
new file mode 100644
index 0000000..40327b4
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma.java
@@ -0,0 +1,291 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.enigma;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Random;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.enigma.parts.EntryWheel;
+import de.vanitasvitae.enigmandroid.enigma.parts.Reflector;
+import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
+
+/**
+ * Main component of the Enigma machine
+ * This is the mostly abstract base of any enigma machine.
+ * Copyright (C) 2015 Paul Schaub
+ */
+public abstract class Enigma
+{
+ static String machineType;
+
+ boolean doAnomaly = false; //Has the time come to handle an anomaly?
+
+ ArrayList availableEntryWheels;
+ ArrayList availableRotors;
+ ArrayList availableReflectors;
+
+ Random rand;
+
+ Enigma()
+ {
+ establishAvailableParts();
+ initialize();
+ }
+
+ /**
+ * In this method, available EntryWheels, Rotors and Reflectors can be defined.
+ */
+ protected abstract void establishAvailableParts();
+
+ /**
+ * Add a Rotor to the ArrayList of available rotors for this machine.
+ * Also set the index of the Rotor.
+ * @param r Rotor
+ */
+ void addAvailableRotor(Rotor r)
+ {
+ if(availableRotors == null) availableRotors = new ArrayList<>();
+ availableRotors.add(availableRotors.size(), r.setIndex(availableRotors.size()));
+ }
+
+ void addAvailableEntryWheel(EntryWheel e)
+ {
+ if(availableEntryWheels == null) availableEntryWheels = new ArrayList<>();
+ availableEntryWheels.add(availableEntryWheels.size(), e.setIndex(availableEntryWheels.size()));
+ }
+
+ void addAvailableReflector(Reflector r)
+ {
+ if(availableReflectors == null) availableReflectors = new ArrayList<>();
+ availableReflectors.add(availableReflectors.size(), r.setIndex(availableReflectors.size()));
+ }
+
+ public ArrayList getAvailableEntryWheels()
+ {
+ return availableEntryWheels;
+ }
+
+ public ArrayList getAvailableRotors()
+ {
+ return availableRotors;
+ }
+
+ public ArrayList getAvailableReflectors()
+ {
+ return availableReflectors;
+ }
+
+ EntryWheel getEntryWheel(int index)
+ {
+ if(availableEntryWheels == null || availableEntryWheels.size() == 0) return null;
+ return availableEntryWheels.get(index % availableEntryWheels.size()).getInstance();
+ }
+
+ Rotor getRotor(int index)
+ {
+ if(availableRotors == null || availableRotors.size() == 0) return null;
+ return availableRotors.get(index % availableRotors.size()).getInstance();
+ }
+
+ Rotor getRotor(int index, int rotation, int ringSetting)
+ {
+ return getRotor(index).setRotation(rotation).setRingSetting(ringSetting);
+ }
+
+ Reflector getReflector(int index)
+ {
+ if(availableReflectors == null || availableReflectors.size() == 0) return null;
+ return availableReflectors.get(index%availableReflectors.size()).getInstance();
+ }
+
+ Reflector getReflector(int index, int rotation, int ringSetting)
+ {
+ return getReflector(index).setRotation(rotation).setRingSetting(ringSetting);
+ }
+
+ /**
+ * Set the enigma to an initial state
+ */
+ protected abstract void initialize();
+
+ /**
+ * Encrypt / Decrypt a given String w.
+ * w must be prepared using prepare(w) beforehand.
+ * Doing so changes the state of the rotors but not the state of the plugboard and the
+ * ringSettings
+ *
+ * @param w Text to decrypt/encryptString
+ * @return encrypted/decrypted string
+ */
+ public String encryptString(String w)
+ {
+ //output string
+ String output = "";
+ //for each char x in k
+ for (char x : w.toCharArray())
+ {
+ output = output + this.encryptChar(x);
+ }
+ //return en-/decrypted string
+ return output;
+ }
+
+ /**
+ * Set the enigma into the next mechanical state.
+ * This rotates the first rotor and eventually also the second/third.
+ * Also this method handles the anomaly in case it should happen.
+ */
+ public abstract void nextState();
+
+ /**
+ * Set the enigma into a completely random state using a unseeded SecureRandom object.
+ */
+ public void randomState()
+ {
+ this.rand = ((MainActivity) (MainActivity.ActivitySingleton.getInstance().getActivity()))
+ .getSecureRandom();
+ generateState();
+ }
+
+ /**
+ * Set the enigma to a random state based on the initialization of rand.
+ * Don not choose a rotor twice, set random rotations, ringSettings, ukw and possibly
+ * plugboard / rewirable ukw configurations.
+ */
+ protected abstract void generateState();
+
+ /**
+ * Substitute char k by sending the signal through the enigma.
+ * The signal passes the plugboard, the rotors and returns back after going through the
+ * reflector wheel.
+ *
+ * @param k input char
+ * @return substituted output char
+ */
+ protected abstract char encryptChar(char k);
+
+ /**
+ * Set the state of the enigma
+ * @param state new state
+ */
+ public abstract void setState(EnigmaStateBundle state);
+
+ /**
+ * Return an object representing the current state of the enigma
+ * @return state
+ */
+ public abstract EnigmaStateBundle getState();
+
+ /**
+ * Set the rand into a certain state based on seed.
+ * Then set the enigmas state.
+ * @param seed passphrase
+ */
+ public void setStateFromSeed(String seed)
+ {
+ rand = new Random(seed.hashCode());
+ generateState();
+ }
+
+ public abstract void restoreState(BigInteger mem, int protocol_version);
+
+ public BigInteger getEncodedState()
+ {
+ return getEncodedState(MainActivity.latest_protocol_version);
+ }
+ protected abstract BigInteger getEncodedState(int protocol_version);
+
+ private static String numToMachineType(int n)
+ {
+ int m = 13;
+ n = (m+(n+m)%m)%m; //Problem? Trolololo
+ switch (n) {
+ case 0: return "I";
+ case 1: return "M3";
+ case 2: return "M4";
+ case 3: return "G31";
+ case 4: return "G312";
+ case 5: return "G260";
+ case 6: return "D";
+ case 7: return "K";
+ case 8: return "KS";
+ case 9: return "KSA";
+ case 10: return "R";
+ case 11: return "T";
+ case 12: return "KD";
+ default: return "KD";
+ }
+ }
+
+ public static String chooseEnigmaFromSeed(String seed)
+ {
+ return numToMachineType(seed.hashCode() % 13);
+ }
+
+ public static String chooseEnigmaFromSave(BigInteger save)
+ {
+ return numToMachineType(getValue(save, 20));
+ }
+
+ /**
+ * Return the name indicator of the enigma machine
+ * @return name
+ */
+ public String getMachineType()
+ {
+ return machineType;
+ }
+
+ /**
+ *
+ * @param s source
+ * @param d domain (max value) of the value
+ * @return value
+ */
+ public static int getValue(BigInteger s, int d)
+ {
+ BigInteger o = s.mod(BigInteger.valueOf(d)).add(BigInteger.valueOf(d)).mod(BigInteger.valueOf(d));
+ return Integer.valueOf(o.toString());
+ }
+
+ /**
+ * remove a digit of domain d from source s
+ * @param s source
+ * @param d domain (max value)
+ * @return trimmed source
+ */
+ public static BigInteger removeDigit(BigInteger s, int d)
+ {
+ s = s.subtract(s.mod(BigInteger.valueOf(d)));
+ s = s.divide(BigInteger.valueOf(d));
+ return s;
+ }
+
+ /**
+ *
+ * @param s source
+ * @param b base (max value)
+ * @param v actual value
+ * @return lengthened source
+ */
+ public static BigInteger addDigit(BigInteger s, int v, int b)
+ {
+ s = s.multiply(BigInteger.valueOf(b));
+ s = s.add(BigInteger.valueOf(v % b));
+ return s;
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/EnigmaStateBundle.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/EnigmaStateBundle.java
new file mode 100644
index 0000000..98a8261
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/EnigmaStateBundle.java
@@ -0,0 +1,208 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.enigma;
+
+/**
+ * Class that contains a possible state of an enigma machine.
+ * Used to store and transport configuration and settings.
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class EnigmaStateBundle{
+ private String machineType;
+
+ private int typeEntryWheel;
+
+ private int typeRotor1;
+ private int typeRotor2;
+ private int typeRotor3;
+ private int typeRotor4;
+
+ private int rotationRotor1;
+ private int rotationRotor2;
+ private int rotationRotor3;
+ private int rotationRotor4;
+
+ private int ringSettingRotor1;
+ private int ringSettingRotor2;
+ private int ringSettingRotor3;
+ private int ringSettingRotor4;
+
+ private int typeReflector;
+
+ private int rotationReflector;
+ private int ringSettingReflector;
+
+ private int[] configurationPlugboard;
+
+ private int[] configurationReflector;
+
+// --Commented out by Inspection START (07.11.15 19:46):
+// public String getMachineType()
+// {
+// return this.machineType;
+// }
+// --Commented out by Inspection STOP (07.11.15 19:46)
+
+// --Commented out by Inspection START (07.11.15 19:46):
+// public void setMachineType(String type)
+// {
+// this.machineType = type;
+// }
+// --Commented out by Inspection STOP (07.11.15 19:46)
+
+ public int getTypeRotor1() {
+ return typeRotor1;
+ }
+
+ public void setTypeRotor1(int typeRotor1) {
+ this.typeRotor1 = typeRotor1;
+ }
+
+ public int getTypeRotor2() {
+ return typeRotor2;
+ }
+
+ public void setTypeRotor2(int typeRotor2) {
+ this.typeRotor2 = typeRotor2;
+ }
+
+ public int getTypeRotor3() {
+ return typeRotor3;
+ }
+
+ public void setTypeRotor3(int typeRotor3) {
+ this.typeRotor3 = typeRotor3;
+ }
+
+ public int getTypeRotor4() {
+ return typeRotor4;
+ }
+
+ public void setTypeRotor4(int typeRotor4) {
+ this.typeRotor4 = typeRotor4;
+ }
+
+ public int getRotationRotor1() {
+ return rotationRotor1;
+ }
+
+ public void setRotationRotor1(int rotationRotor1) {
+ this.rotationRotor1 = rotationRotor1;
+ }
+
+ public int getRotationRotor2() {
+ return rotationRotor2;
+ }
+
+ public void setRotationRotor2(int rotationRotor2) {
+ this.rotationRotor2 = rotationRotor2;
+ }
+
+ public int getRotationRotor3() {
+ return rotationRotor3;
+ }
+
+ public void setRotationRotor3(int rotationRotor3) {
+ this.rotationRotor3 = rotationRotor3;
+ }
+
+ public int getRotationRotor4() {
+ return rotationRotor4;
+ }
+
+ public void setRotationRotor4(int rotationRotor4) {
+ this.rotationRotor4 = rotationRotor4;
+ }
+
+ public int getRingSettingRotor1() {
+ return ringSettingRotor1;
+ }
+
+ public void setRingSettingRotor1(int ringSettingRotor1) {
+ this.ringSettingRotor1 = ringSettingRotor1;
+ }
+
+ public int getRingSettingRotor2() {
+ return ringSettingRotor2;
+ }
+
+ public void setRingSettingRotor2(int ringSettingRotor2) {
+ this.ringSettingRotor2 = ringSettingRotor2;
+ }
+
+ public int getRingSettingRotor3() {
+ return ringSettingRotor3;
+ }
+
+ public void setRingSettingRotor3(int ringSettingRotor3) {
+ this.ringSettingRotor3 = ringSettingRotor3;
+ }
+
+ public int getRingSettingRotor4() {
+ return ringSettingRotor4;
+ }
+
+ public void setRingSettingRotor4(int ringSettingRotor4) {
+ this.ringSettingRotor4 = ringSettingRotor4;
+ }
+
+ public int getTypeReflector() {
+ return typeReflector;
+ }
+
+ public void setTypeReflector(int typeReflector) {
+ this.typeReflector = typeReflector;
+ }
+
+ public int getTypeEntryWheel() {
+ return typeEntryWheel;
+ }
+
+ public void setTypeEntryWheel(int typeEntryWheel) {
+ this.typeEntryWheel = typeEntryWheel;
+ }
+
+ public int[] getConfigurationPlugboard() {
+ return configurationPlugboard;
+ }
+
+ public void setConfigurationPlugboard(int[] configurationPlugboard) {
+ this.configurationPlugboard = configurationPlugboard;
+ }
+
+ public int[] getConfigurationReflector() {
+ return configurationReflector;
+ }
+
+ public void setConfigurationReflector(int[] configurationReflector) {
+ this.configurationReflector = configurationReflector;
+ }
+
+ public int getRotationReflector() {
+ return rotationReflector;
+ }
+
+ public void setRotationReflector(int rotationReflector) {
+ this.rotationReflector = rotationReflector;
+ }
+
+ public int getRingSettingReflector() {
+ return ringSettingReflector;
+ }
+
+ public void setRingSettingReflector(int ringSettingReflector) {
+ this.ringSettingReflector = ringSettingReflector;
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_D.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_D.java
new file mode 100644
index 0000000..1cfa89e
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_D.java
@@ -0,0 +1,221 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.enigma;
+
+import android.util.Log;
+
+import java.math.BigInteger;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.enigma.parts.EntryWheel;
+import de.vanitasvitae.enigmandroid.enigma.parts.Plugboard;
+import de.vanitasvitae.enigmandroid.enigma.parts.Reflector;
+import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
+
+/**
+ * Concrete implementation of an enigma machine of name D
+ * This machine has a rewirable UKW, non changeable rotors.
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class Enigma_D extends Enigma {
+
+ private EntryWheel entryWheel;
+ private Rotor rotor1;
+ private Rotor rotor2;
+ private Rotor rotor3;
+ private Reflector reflector;
+
+ public Enigma_D()
+ {
+ super();
+ machineType = "D";
+ Log.d(MainActivity.APP_ID, "Created Enigma D");
+ }
+
+ @Override
+ protected void establishAvailableParts()
+ {
+ addAvailableEntryWheel(new EntryWheel.EntryWheel_QWERTZ());
+
+ addAvailableRotor(new Rotor.Rotor_K_D_I(0, 0));
+ addAvailableRotor(new Rotor.Rotor_K_D_II(0, 0));
+ addAvailableRotor(new Rotor.Rotor_K_D_III(0, 0));
+
+ addAvailableReflector(new Reflector.ReflectorEnigma_D_G31());
+ }
+
+ @Override
+ public void initialize()
+ {
+ this.entryWheel = availableEntryWheels.get(0);
+ this.rotor1 = availableRotors.get(0);
+ this.rotor2 = availableRotors.get(1);
+ this.rotor3 = availableRotors.get(2);
+ this.reflector = availableReflectors.get(0);
+ }
+
+ @Override
+ public void nextState()
+ {
+ rotor1.rotate();
+ if (rotor1.isAtTurnoverPosition() || this.doAnomaly)
+ {
+ rotor2.rotate();
+ this.doAnomaly = rotor2.doubleTurnAnomaly();
+ if (rotor2.isAtTurnoverPosition())
+ {
+ rotor3.rotate();
+ }
+ }
+ }
+
+ @Override
+ protected void generateState() {
+ int rot1 = rand.nextInt(26);
+ int rot2 = rand.nextInt(26);
+ int rot3 = rand.nextInt(26);
+ int rotRef = rand.nextInt(26);
+ int ring1 = rand.nextInt(26);
+ int ring2 = rand.nextInt(26);
+ int ring3 = rand.nextInt(26);
+ int ringRef = rand.nextInt(26);
+
+ this.rotor1.setRotation(rot1).setRingSetting(ring1);
+ this.rotor2.setRotation(rot2).setRingSetting(ring2);
+ this.rotor3.setRotation(rot3).setRingSetting(ring3);
+
+ this.reflector.setRotation(rotRef).setRingSetting(ringRef)
+ .setConfiguration(Plugboard.seedToReflectorConfiguration(rand));
+ }
+
+ @Override
+ public char encryptChar(char k)
+ {
+ nextState();
+ int x = ((int) k)-65; //Cast to int and remove Unicode Offset (A=65 in Unicode.)
+ //Encryption
+ //forward direction
+ x = entryWheel.encryptForward(x);
+ x = rotor1.normalize(x + rotor1.getRotation() - rotor1.getRingSetting());
+ x = rotor1.encryptForward(x);
+ x = rotor1.normalize(x - rotor1.getRotation() + rotor1.getRingSetting() + rotor2.getRotation() - rotor2.getRingSetting());
+ x = rotor2.encryptForward(x);
+ x = rotor1.normalize(x - rotor2.getRotation() + rotor2.getRingSetting() + rotor3.getRotation() - rotor3.getRingSetting());
+ x = rotor3.encryptForward(x);
+ x = rotor1.normalize(x - rotor3.getRotation() + rotor3.getRingSetting() + reflector.getRotation() - reflector.getRingSetting());
+ //backward direction
+ x = reflector.encrypt(x);
+ x = rotor1.normalize(x + rotor3.getRotation() - rotor3.getRingSetting() - reflector.getRotation() + reflector.getRingSetting());
+ x = rotor3.encryptBackward(x);
+ x = rotor1.normalize(x + rotor2.getRotation() - rotor2.getRingSetting() - rotor3.getRotation() + rotor3.getRingSetting());
+ x = rotor2.encryptBackward(x);
+ x = rotor1.normalize(x + rotor1.getRotation() - rotor1.getRingSetting() - rotor2.getRotation() + rotor2.getRingSetting());
+ x = rotor1.encryptBackward(x);
+ x = rotor1.normalize(x - rotor1.getRotation() + rotor1.getRingSetting());
+ x = entryWheel.encryptBackward(x);
+ return (char) (x + 65); //Add Offset again, cast back to char and return
+ }
+
+ @Override
+ public void setState(EnigmaStateBundle state)
+ {
+ this.entryWheel = getEntryWheel(state.getTypeEntryWheel());
+ this.rotor1 = getRotor(state.getTypeRotor1(), state.getRotationRotor1(), state.getRingSettingRotor1());
+ this.rotor2 = getRotor(state.getTypeRotor2(), state.getRotationRotor2(), state.getRingSettingRotor2());
+ this.rotor3 = getRotor(state.getTypeRotor3(), state.getRotationRotor3(), state.getRingSettingRotor3());
+ this.reflector = getReflector(state.getTypeReflector(),
+ state.getRotationReflector(),
+ state.getRingSettingReflector())
+ .setConfiguration(state.getConfigurationReflector());
+ }
+
+ @Override
+ public EnigmaStateBundle getState()
+ {
+ EnigmaStateBundle state = new EnigmaStateBundle();
+
+ state.setTypeEntryWheel(entryWheel.getIndex());
+
+ state.setTypeRotor1(rotor1.getIndex());
+ state.setTypeRotor2(rotor2.getIndex());
+ state.setTypeRotor3(rotor3.getIndex());
+
+ state.setRotationRotor1(rotor1.getRotation());
+ state.setRotationRotor2(rotor2.getRotation());
+ state.setRotationRotor3(rotor3.getRotation());
+
+ state.setRingSettingRotor1(rotor1.getRingSetting());
+ state.setRingSettingRotor2(rotor2.getRingSetting());
+ state.setRingSettingRotor3(rotor3.getRingSetting());
+
+ state.setTypeReflector(reflector.getIndex());
+ state.setRotationReflector(reflector.getRotation());
+ state.setRingSettingReflector(reflector.getRingSetting());
+ state.setConfigurationReflector(reflector.getConfiguration());
+
+ return state;
+ }
+
+ @Override
+ public void restoreState(BigInteger s, int protocol_version)
+ {
+ switch(protocol_version)
+ {
+ case 1:
+ int rot1 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int ring1 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int rot2 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int ring2 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int rot3 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int ring3 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int rotRef = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int ringRef = getValue(s, 26);
+ s = removeDigit(s, 26);
+
+ this.rotor1 = getRotor(0, rot1, ring1);
+ this.rotor2 = getRotor(1, rot2, ring2);
+ this.rotor3 = getRotor(2, rot3, ring3);
+ this.reflector = getReflector(0, rotRef, ringRef);
+ this.reflector.setConfiguration(s);
+ break;
+
+ default: Log.e(MainActivity.APP_ID, "Unsupported protocol version "+protocol_version);
+ }
+ }
+
+ @Override
+ public BigInteger getEncodedState(int protocol_version) {
+ BigInteger s = Plugboard.configurationToBigInteger(reflector.getConfiguration());
+ s = addDigit(s, reflector.getRingSetting(), 26);
+ s = addDigit(s, reflector.getRotation(), 26);
+ s = addDigit(s, rotor3.getRingSetting(), 26);
+ s = addDigit(s, rotor3.getRotation(), 26);
+ s = addDigit(s, rotor2.getRingSetting(), 26);
+ s = addDigit(s, rotor2.getRotation(), 26);
+ s = addDigit(s, rotor1.getRingSetting(), 26);
+ s = addDigit(s, rotor1.getRotation(), 26);
+
+ s = addDigit(s, 6, 20); //Machine #6
+ s = addDigit(s, protocol_version, MainActivity.max_protocol_version);
+ return s;
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_G260.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_G260.java
new file mode 100644
index 0000000..50492fe
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_G260.java
@@ -0,0 +1,70 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.enigma;
+
+import android.util.Log;
+
+import java.math.BigInteger;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.enigma.parts.EntryWheel;
+import de.vanitasvitae.enigmandroid.enigma.parts.Reflector;
+import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
+
+/**
+ * Implementation of the Enigma machine of name G31 (Abwehr)
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class Enigma_G260 extends Enigma_G31
+{
+ public Enigma_G260()
+ {
+ super();
+ machineType = "G260";
+ Log.d(MainActivity.APP_ID, "Created Enigma G260");
+ }
+
+ @Override
+ protected void establishAvailableParts()
+ {
+ addAvailableEntryWheel(new EntryWheel.EntryWheel_QWERTZ());
+ addAvailableRotor(new Rotor.Rotor_G260_I(0, 0));
+ addAvailableRotor(new Rotor.Rotor_G260_II(0, 0));
+ addAvailableRotor(new Rotor.Rotor_G260_III(0, 0));
+ addAvailableReflector(new Reflector.Reflector_K_G260());
+ }
+
+ @Override
+ public BigInteger getEncodedState(int protocol_version)
+ {
+ BigInteger s = BigInteger.valueOf(reflector.getRingSetting());
+ s = addDigit(s, reflector.getRotation(), 26);
+ s = addDigit(s, rotor3.getRingSetting(), 26);
+ s = addDigit(s, rotor3.getRotation(), 26);
+ s = addDigit(s, rotor2.getRingSetting(), 26);
+ s = addDigit(s, rotor2.getRotation(), 26);
+ s = addDigit(s, rotor1.getRingSetting(), 26);
+ s = addDigit(s, rotor1.getRotation(), 26);
+
+ s = addDigit(s, rotor3.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor2.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor1.getIndex(), availableRotors.size());
+
+ s = addDigit(s, 5, 20); //Machine #5
+ s = addDigit(s, protocol_version, MainActivity.max_protocol_version);
+
+ return s;
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_G31.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_G31.java
new file mode 100644
index 0000000..4928f73
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_G31.java
@@ -0,0 +1,230 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.enigma;
+
+import android.util.Log;
+
+import java.math.BigInteger;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.enigma.parts.EntryWheel;
+import de.vanitasvitae.enigmandroid.enigma.parts.Reflector;
+import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
+
+/**
+ * Implementation of the Enigma machine of name G31 (Abwehr)
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class Enigma_G31 extends Enigma
+{
+ private EntryWheel entryWheel;
+ Rotor rotor1;
+ Rotor rotor2;
+ Rotor rotor3;
+ Reflector reflector;
+
+ public Enigma_G31()
+ {
+ super();
+ machineType = "G31";
+ Log.d(MainActivity.APP_ID, "Created Enigma G31");
+ }
+
+ @Override
+ protected void establishAvailableParts()
+ {
+ addAvailableEntryWheel(new EntryWheel.EntryWheel_QWERTZ());
+ addAvailableRotor(new Rotor.Rotor_G31_I(0, 0));
+ addAvailableRotor(new Rotor.Rotor_G31_II(0, 0));
+ addAvailableRotor(new Rotor.Rotor_G31_III(0, 0));
+ addAvailableReflector(new Reflector.ReflectorEnigma_D_G31());
+ }
+
+ @Override
+ public void initialize()
+ {
+ this.entryWheel = getEntryWheel(0);
+ this.rotor1 = getRotor(0);
+ this.rotor2 = getRotor(1);
+ this.rotor3 = getRotor(2);
+ this.reflector = getReflector(0);
+ }
+
+ @Override
+ public void nextState()
+ {
+ rotor1.rotate();
+ if (rotor1.isAtTurnoverPosition())
+ {
+ rotor2.rotate();
+ if (rotor2.isAtTurnoverPosition())
+ {
+ rotor3.rotate();
+ if(rotor3.isAtTurnoverPosition())
+ {
+ reflector.setRotation(reflector.getRotation()+1);
+ }
+ }
+ }
+ }
+
+ protected void generateState()
+ {
+ int r1, r2=-1, r3;
+ r1 = rand.nextInt(3);
+ while(r2 == -1 || r2 == r1) r2 = rand.nextInt(3);
+ r3 = 3 - r1 - r2;
+
+ int rot1 = rand.nextInt(26);
+ int rot2 = rand.nextInt(26);
+ int rot3 = rand.nextInt(26);
+ int rotRef = rand.nextInt(26);
+ int ring1 = rand.nextInt(26);
+ int ring2 = rand.nextInt(26);
+ int ring3 = rand.nextInt(26);
+ int ringRef = rand.nextInt(26);
+
+ this.entryWheel = getEntryWheel(0);
+ this.rotor1 = getRotor(r1, rot1, ring1);
+ this.rotor2 = getRotor(r2, rot2, ring2);
+ this.rotor3 = getRotor(r3, rot3, ring3);
+ this.reflector = getReflector(0, rotRef, ringRef);
+ }
+
+ @Override
+ public char encryptChar(char k) {
+ nextState();
+ int x = ((int) k)-65; //Cast to int and remove Unicode Offset (A=65 in Unicode.)
+ //Encryption
+ //forward direction
+ x = entryWheel.encryptForward(x);
+ x = rotor1.normalize(x + rotor1.getRotation() - rotor1.getRingSetting());
+ x = rotor1.encryptForward(x);
+ x = rotor1.normalize(x - rotor1.getRotation() + rotor1.getRingSetting() + rotor2.getRotation() - rotor2.getRingSetting());
+ x = rotor2.encryptForward(x);
+ x = rotor1.normalize(x - rotor2.getRotation() + rotor2.getRingSetting() + rotor3.getRotation() - rotor3.getRingSetting());
+ x = rotor3.encryptForward(x);
+ x = rotor1.normalize(x - rotor3.getRotation() + rotor3.getRingSetting() + reflector.getRotation() - reflector.getRingSetting());
+ //backward direction
+ x = reflector.encrypt(x);
+ x = rotor1.normalize(x + rotor3.getRotation() - rotor3.getRingSetting() - reflector.getRotation() + reflector.getRingSetting());
+ x = rotor3.encryptBackward(x);
+ x = rotor1.normalize(x + rotor2.getRotation() - rotor2.getRingSetting() - rotor3.getRotation() + rotor3.getRingSetting());
+ x = rotor2.encryptBackward(x);
+ x = rotor1.normalize(x + rotor1.getRotation() - rotor1.getRingSetting() - rotor2.getRotation() + rotor2.getRingSetting());
+ x = rotor1.encryptBackward(x);
+ x = rotor1.normalize(x - rotor1.getRotation() + rotor1.getRingSetting());
+ x = entryWheel.encryptBackward(x);
+ return (char) (x + 65); //Add Offset again, cast back to char and return
+ }
+
+ @Override
+ public void setState(EnigmaStateBundle state)
+ {
+ this.entryWheel = getEntryWheel(state.getTypeEntryWheel());
+ this.rotor1 = getRotor(state.getTypeRotor1(), state.getRotationRotor1(), state.getRingSettingRotor1());
+ this.rotor2 = getRotor(state.getTypeRotor2(), state.getRotationRotor2(), state.getRingSettingRotor2());
+ this.rotor3 = getRotor(state.getTypeRotor3(), state.getRotationRotor3(), state.getRingSettingRotor3());
+ this.reflector = getReflector(state.getTypeReflector(),
+ state.getRotationReflector(), state.getRingSettingReflector());
+ }
+
+ @Override
+ public EnigmaStateBundle getState() {
+ EnigmaStateBundle state = new EnigmaStateBundle();
+
+ state.setTypeEntryWheel(entryWheel.getIndex());
+
+ state.setTypeRotor1(rotor1.getIndex());
+ state.setTypeRotor2(rotor2.getIndex());
+ state.setTypeRotor3(rotor3.getIndex());
+
+ state.setRotationRotor1(rotor1.getRotation());
+ state.setRotationRotor2(rotor2.getRotation());
+ state.setRotationRotor3(rotor3.getRotation());
+
+ state.setRingSettingRotor1(rotor1.getRingSetting());
+ state.setRingSettingRotor2(rotor2.getRingSetting());
+ state.setRingSettingRotor3(rotor3.getRingSetting());
+
+ state.setTypeReflector(reflector.getIndex());
+ state.setRotationReflector(reflector.getRotation());
+ state.setRingSettingReflector(reflector.getRingSetting());
+
+ return state;
+ }
+
+ @Override
+ public void restoreState(BigInteger s, int protocol_version)
+ {
+ switch (protocol_version)
+ {
+ case 1:
+ int r1 = getValue(s, availableRotors.size());
+ s = removeDigit(s, availableRotors.size());
+ int r2 = getValue(s, availableRotors.size());
+ s = removeDigit(s, availableRotors.size());
+ int r3 = getValue(s, availableRotors.size());
+ s = removeDigit(s, availableRotors.size());
+
+ int rot1 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int ring1 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int rot2 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int ring2 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int rot3 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int ring3 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int rotRef = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int ringRef = getValue(s, 26);
+
+
+ this.entryWheel = getEntryWheel(0);
+ this.rotor1 = getRotor(r1, rot1, ring1);
+ this.rotor2 = getRotor(r2, rot2, ring2);
+ this.rotor3 = getRotor(r3, rot3, ring3);
+ this.reflector = getReflector(0, rotRef, ringRef);
+ break;
+
+ default: Log.e(MainActivity.APP_ID, "Unsupported protocol version "+protocol_version);
+ }
+ }
+
+ @Override
+ public BigInteger getEncodedState(int protocol_version)
+ {
+ BigInteger s = BigInteger.valueOf(reflector.getRingSetting());
+ s = addDigit(s, reflector.getRotation(), 26);
+ s = addDigit(s, rotor3.getRingSetting(), 26);
+ s = addDigit(s, rotor3.getRotation(), 26);
+ s = addDigit(s, rotor2.getRingSetting(), 26);
+ s = addDigit(s, rotor2.getRotation(), 26);
+ s = addDigit(s, rotor1.getRingSetting(), 26);
+ s = addDigit(s, rotor1.getRotation(), 26);
+
+ s = addDigit(s, rotor3.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor2.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor1.getIndex(), availableRotors.size());
+
+ s = addDigit(s, 3, 20); //Machine #3
+ s = addDigit(s, protocol_version, MainActivity.max_protocol_version);
+ return s;
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_G312.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_G312.java
new file mode 100644
index 0000000..93e0294
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_G312.java
@@ -0,0 +1,70 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.enigma;
+
+import android.util.Log;
+
+import java.math.BigInteger;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.enigma.parts.EntryWheel;
+import de.vanitasvitae.enigmandroid.enigma.parts.Reflector;
+import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
+
+/**
+ * Implementation of the Enigma machine of name G31 (Abwehr)
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class Enigma_G312 extends Enigma_G31
+{
+ public Enigma_G312()
+ {
+ super();
+ machineType = "G312";
+ Log.d(MainActivity.APP_ID, "Created Enigma G312");
+ }
+
+ @Override
+ protected void establishAvailableParts()
+ {
+ addAvailableEntryWheel(new EntryWheel.EntryWheel_QWERTZ());
+ addAvailableRotor(new Rotor.Rotor_G312_I(0, 0));
+ addAvailableRotor(new Rotor.Rotor_G312_II(0, 0));
+ addAvailableRotor(new Rotor.Rotor_G312_III(0, 0));
+ addAvailableReflector(new Reflector.Reflector_G312());
+ }
+
+ @Override
+ public BigInteger getEncodedState(int protocol_version)
+ {
+ BigInteger s = BigInteger.valueOf(reflector.getRingSetting());
+ s = addDigit(s, reflector.getRotation(), 26);
+ s = addDigit(s, rotor3.getRingSetting(), 26);
+ s = addDigit(s, rotor3.getRotation(), 26);
+ s = addDigit(s, rotor2.getRingSetting(), 26);
+ s = addDigit(s, rotor2.getRotation(), 26);
+ s = addDigit(s, rotor1.getRingSetting(), 26);
+ s = addDigit(s, rotor1.getRotation(), 26);
+
+ s = addDigit(s, rotor3.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor2.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor1.getIndex(), availableRotors.size());
+
+ s = addDigit(s, 4, 20); //Machine #4
+ s = addDigit(s, protocol_version, MainActivity.max_protocol_version);
+
+ return s;
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_I.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_I.java
new file mode 100644
index 0000000..5117d63
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_I.java
@@ -0,0 +1,239 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.enigma;
+
+import android.util.Log;
+
+import java.math.BigInteger;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.enigma.parts.EntryWheel;
+import de.vanitasvitae.enigmandroid.enigma.parts.Plugboard;
+import de.vanitasvitae.enigmandroid.enigma.parts.Reflector;
+import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
+
+/**
+ * Concrete implementation of an enigma machine of name I
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class Enigma_I extends Enigma
+{
+ EntryWheel entryWheel;
+ Rotor rotor1;
+ Rotor rotor2;
+ Rotor rotor3;
+ Reflector reflector;
+
+ Plugboard plugboard;
+
+ public Enigma_I()
+ {
+ super();
+ machineType = "I";
+ Log.d(MainActivity.APP_ID, "Created Enigma I");
+ }
+
+ @Override
+ protected void establishAvailableParts() {
+ addAvailableEntryWheel(new EntryWheel.EntryWheel_ABCDEF());
+ addAvailableRotor(new Rotor.Rotor_I(0, 0));
+ addAvailableRotor(new Rotor.Rotor_II(0,0));
+ addAvailableRotor(new Rotor.Rotor_III(0,0));
+ addAvailableRotor(new Rotor.Rotor_IV(0,0));
+ addAvailableRotor(new Rotor.Rotor_V(0,0));
+ addAvailableReflector(new Reflector.Reflector_A());
+ addAvailableReflector(new Reflector.Reflector_B());
+ addAvailableReflector(new Reflector.Reflector_C());
+ }
+
+ @Override
+ public void initialize()
+ {
+ this.plugboard= new Plugboard();
+ this.entryWheel = getEntryWheel(0);
+ this.rotor1 = getRotor(0, 0, 0);
+ this.rotor2 = getRotor(1, 0, 0);
+ this.rotor3 = getRotor(2, 0, 0);
+ this.reflector = getReflector(0);
+ }
+
+ @Override
+ public void nextState()
+ {
+ rotor1.rotate();
+ if (rotor1.isAtTurnoverPosition() || this.doAnomaly)
+ {
+ rotor2.rotate();
+ this.doAnomaly = rotor2.doubleTurnAnomaly();
+ if (rotor2.isAtTurnoverPosition())
+ {
+ rotor3.rotate();
+ }
+ }
+ }
+
+ @Override
+ protected void generateState() {
+ int r1, r2=-1, r3=-1;
+ r1 = rand.nextInt(5);
+ while(r2 == -1 || r2 == r1) r2 = rand.nextInt(5);
+ while(r3 == -1 || r3 == r2 || r3 == r1) r3 = rand.nextInt(5);
+ int ref = rand.nextInt(3);
+
+ int rot1 = rand.nextInt(26);
+ int rot2 = rand.nextInt(26);
+ int rot3 = rand.nextInt(26);
+ int ring1 = rand.nextInt(26);
+ int ring2 = rand.nextInt(26);
+ int ring3 = rand.nextInt(26);
+
+ this.rotor1 = getRotor(r1, rot1, ring1);
+ this.rotor2 = getRotor(r2, rot2, ring2);
+ this.rotor3 = getRotor(r3, rot3, ring3);
+ this.reflector = getReflector(ref);
+
+ this.plugboard = new Plugboard();
+ plugboard.setConfiguration(Plugboard.seedToPlugboardConfiguration(rand));
+ }
+
+ @Override
+ public char encryptChar(char k)
+ {
+ nextState();
+ int x = ((int) k)-65; //Cast to int and remove Unicode Offset (A=65 in Unicode.)
+ //Encryption
+ //forward direction
+ x = plugboard.encrypt(x);
+ x = entryWheel.encryptForward(x);
+ x = rotor1.normalize(x + rotor1.getRotation() - rotor1.getRingSetting());
+ x = rotor1.encryptForward(x);
+ x = rotor1.normalize(x - rotor1.getRotation() + rotor1.getRingSetting() + rotor2.getRotation() - rotor2.getRingSetting());
+ x = rotor2.encryptForward(x);
+ x = rotor1.normalize(x - rotor2.getRotation() + rotor2.getRingSetting() + rotor3.getRotation() - rotor3.getRingSetting());
+ x = rotor3.encryptForward(x);
+ x = rotor1.normalize(x - rotor3.getRotation() + rotor3.getRingSetting());
+ //backward direction
+ x = reflector.encrypt(x);
+ x = rotor1.normalize(x + rotor3.getRotation() - rotor3.getRingSetting());
+ x = rotor3.encryptBackward(x);
+ x = rotor1.normalize(x + rotor2.getRotation() - rotor2.getRingSetting() - rotor3.getRotation() + rotor3.getRingSetting());
+ x = rotor2.encryptBackward(x);
+ x = rotor1.normalize(x + rotor1.getRotation() - rotor1.getRingSetting() - rotor2.getRotation() + rotor2.getRingSetting());
+ x = rotor1.encryptBackward(x);
+ x = rotor1.normalize(x - rotor1.getRotation() + rotor1.getRingSetting());
+ x = entryWheel.encryptBackward(x);
+ x = plugboard.encrypt(x);
+ return (char) (x + 65); //Add Offset again, cast back to char and return
+ }
+
+ @Override
+ public void setState(EnigmaStateBundle state)
+ {
+ plugboard.setConfiguration(state.getConfigurationPlugboard());
+ entryWheel = getEntryWheel(state.getTypeEntryWheel());
+ rotor1 = getRotor(state.getTypeRotor1(), state.getRotationRotor1(), state.getRingSettingRotor1());
+ rotor2 = getRotor(state.getTypeRotor2(), state.getRotationRotor2(), state.getRingSettingRotor2());
+ rotor3 = getRotor(state.getTypeRotor3(), state.getRotationRotor3(), state.getRingSettingRotor3());
+ reflector = getReflector(state.getTypeReflector());
+ }
+
+ @Override
+ public EnigmaStateBundle getState()
+ {
+ EnigmaStateBundle state = new EnigmaStateBundle();
+
+ state.setConfigurationPlugboard(plugboard.getConfiguration());
+
+ state.setTypeEntryWheel(entryWheel.getIndex());
+
+ state.setTypeRotor1(rotor1.getIndex());
+ state.setTypeRotor2(rotor2.getIndex());
+ state.setTypeRotor3(rotor3.getIndex());
+
+ state.setTypeReflector(reflector.getIndex());
+
+ state.setRotationRotor1(rotor1.getRotation());
+ state.setRotationRotor2(rotor2.getRotation());
+ state.setRotationRotor3(rotor3.getRotation());
+
+ state.setRingSettingRotor1(rotor1.getRingSetting());
+ state.setRingSettingRotor2(rotor2.getRingSetting());
+ state.setRingSettingRotor3(rotor3.getRingSetting());
+
+ return state;
+ }
+
+ @Override
+ public void restoreState(BigInteger s, int protocol_version)
+ {
+ switch (protocol_version)
+ {
+ case 1:
+ int r1 = getValue(s, availableRotors.size());
+ s = removeDigit(s, availableRotors.size());
+ int r2 = getValue(s, availableRotors.size());
+ s = removeDigit(s, availableRotors.size());
+ int r3 = getValue(s, availableRotors.size());
+ s = removeDigit(s, availableRotors.size());
+ int ref = getValue(s, availableReflectors.size());
+ s = removeDigit(s, availableReflectors.size());
+ int rot1 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int ring1 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int rot2 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int ring2 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int rot3 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int ring3 = getValue(s, 26);
+ s = removeDigit(s, 26);
+
+ this.entryWheel = getEntryWheel(0);
+ this.rotor1 = getRotor(r1, rot1, ring1);
+ this.rotor2 = getRotor(r2, rot2, ring2);
+ this.rotor3 = getRotor(r3, rot3, ring3);
+ this.reflector = getReflector(ref);
+
+ this.plugboard = new Plugboard();
+ plugboard.setConfiguration(s);
+ break;
+
+ default: Log.e(MainActivity.APP_ID, "Unsupported protocol version "+protocol_version);
+ }
+ }
+
+ @Override
+ public BigInteger getEncodedState(int protocol_version) {
+ BigInteger s = Plugboard.configurationToBigInteger(plugboard.getConfiguration());
+ s = addDigit(s, rotor3.getRingSetting(), 26);
+ s = addDigit(s, rotor3.getRotation(), 26);
+ s = addDigit(s, rotor2.getRingSetting(), 26);
+ s = addDigit(s, rotor2.getRotation(), 26);
+ s = addDigit(s, rotor1.getRingSetting(), 26);
+ s = addDigit(s, rotor1.getRotation(), 26);
+
+ s = addDigit(s, reflector.getIndex(), availableReflectors.size());
+ s = addDigit(s, rotor3.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor2.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor1.getIndex(), availableRotors.size());
+
+ s = addDigit(s, 0, 20); //Machine #0
+ s = addDigit(s, protocol_version, MainActivity.max_protocol_version);
+
+ return s;
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_K.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_K.java
new file mode 100644
index 0000000..1d0ca9c
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_K.java
@@ -0,0 +1,227 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.enigma;
+
+import android.util.Log;
+
+import java.math.BigInteger;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.enigma.parts.EntryWheel;
+import de.vanitasvitae.enigmandroid.enigma.parts.Reflector;
+import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
+
+/**
+ * Implementation of the Enigma machine of name K
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class Enigma_K extends Enigma
+{
+ private EntryWheel entryWheel;
+ Rotor rotor1;
+ Rotor rotor2;
+ Rotor rotor3;
+ Reflector reflector;
+
+ public Enigma_K()
+ {
+ super();
+ machineType = "K";
+ Log.d(MainActivity.APP_ID, "Created Enigma K");
+ }
+
+ @Override
+ protected void establishAvailableParts()
+ {
+ addAvailableEntryWheel(new EntryWheel.EntryWheel_QWERTZ());
+ addAvailableRotor(new Rotor.Rotor_K_D_I(0, 0));
+ addAvailableRotor(new Rotor.Rotor_K_D_II(0,0));
+ addAvailableRotor(new Rotor.Rotor_K_D_III(0,0));
+ addAvailableReflector(new Reflector.Reflector_K_G260());
+ }
+
+ @Override
+ public void initialize()
+ {
+ this.entryWheel = getEntryWheel(0);
+ this.rotor1 = getRotor(0, 0, 0);
+ this.rotor2 = getRotor(1, 0, 0);
+ this.rotor3 = getRotor(2, 0, 0);
+ this.reflector = getReflector(0);
+ }
+
+ @Override
+ public void nextState()
+ {
+ rotor1.rotate();
+ if (rotor1.isAtTurnoverPosition() || this.doAnomaly)
+ {
+ rotor2.rotate();
+ this.doAnomaly = rotor2.doubleTurnAnomaly();
+ if (rotor2.isAtTurnoverPosition())
+ {
+ rotor3.rotate();
+ }
+ }
+ }
+
+ @Override
+ protected void generateState() {
+ int r1, r2=-1, r3;
+ r1 = rand.nextInt(3);
+ while(r2 == -1 || r2 == r1) r2 = rand.nextInt(3);
+ r3 = 3 - r1 - r2;
+
+ int rot1 = rand.nextInt(26);
+ int rot2 = rand.nextInt(26);
+ int rot3 = rand.nextInt(26);
+ int rotRef = rand.nextInt(26);
+ int ring1 = rand.nextInt(26);
+ int ring2 = rand.nextInt(26);
+ int ring3 = rand.nextInt(26);
+ int ringRef = rand.nextInt(26);
+
+ this.entryWheel = getEntryWheel(0);
+ this.rotor1 = getRotor(r1, rot1, ring1);
+ this.rotor2 = getRotor(r2, rot2, ring2);
+ this.rotor3 = getRotor(r3, rot3, ring3);
+ this.reflector = getReflector(0, rotRef, ringRef);
+ }
+
+ @Override
+ public char encryptChar(char k) {
+ nextState();
+ int x = ((int) k)-65; //Cast to int and remove Unicode Offset (A=65 in Unicode.)
+ //Encryption
+ //forward direction
+ x = entryWheel.encryptForward(x);
+ x = rotor1.normalize(x + rotor1.getRotation() - rotor1.getRingSetting());
+ x = rotor1.encryptForward(x);
+ x = rotor1.normalize(x - rotor1.getRotation() + rotor1.getRingSetting() + rotor2.getRotation() - rotor2.getRingSetting());
+ x = rotor2.encryptForward(x);
+ x = rotor1.normalize(x - rotor2.getRotation() + rotor2.getRingSetting() + rotor3.getRotation() - rotor3.getRingSetting());
+ x = rotor3.encryptForward(x);
+ x = rotor1.normalize(x - rotor3.getRotation() + rotor3.getRingSetting() + reflector.getRotation() - reflector.getRingSetting());
+ //backward direction
+ x = reflector.encrypt(x);
+ x = rotor1.normalize(x + rotor3.getRotation() - rotor3.getRingSetting() - reflector.getRotation() + reflector.getRingSetting());
+ x = rotor3.encryptBackward(x);
+ x = rotor1.normalize(x + rotor2.getRotation() - rotor2.getRingSetting() - rotor3.getRotation() + rotor3.getRingSetting());
+ x = rotor2.encryptBackward(x);
+ x = rotor1.normalize(x + rotor1.getRotation() - rotor1.getRingSetting() - rotor2.getRotation() + rotor2.getRingSetting());
+ x = rotor1.encryptBackward(x);
+ x = rotor1.normalize(x - rotor1.getRotation() + rotor1.getRingSetting());
+ x = entryWheel.encryptBackward(x);
+ return (char) (x + 65); //Add Offset again, cast back to char and return
+ }
+
+ @Override
+ public void setState(EnigmaStateBundle state)
+ {
+ this.entryWheel = getEntryWheel(state.getTypeEntryWheel());
+ this.rotor1 = getRotor(state.getTypeRotor1(), state.getRotationRotor1(), state.getRingSettingRotor1());
+ this.rotor2 = getRotor(state.getTypeRotor2(), state.getRotationRotor2(), state.getRingSettingRotor2());
+ this.rotor3 = getRotor(state.getTypeRotor3(), state.getRotationRotor3(), state.getRingSettingRotor3());
+ this.reflector = getReflector(state.getTypeReflector(), state.getRotationReflector(), state.getRingSettingReflector());
+ }
+
+ @Override
+ public EnigmaStateBundle getState()
+ {
+ EnigmaStateBundle state = new EnigmaStateBundle();
+
+ state.setTypeEntryWheel(entryWheel.getIndex());
+
+ state.setTypeRotor1(rotor1.getIndex());
+ state.setTypeRotor2(rotor2.getIndex());
+ state.setTypeRotor3(rotor3.getIndex());
+
+ state.setRotationRotor1(rotor1.getRotation());
+ state.setRotationRotor2(rotor2.getRotation());
+ state.setRotationRotor3(rotor3.getRotation());
+
+ state.setRingSettingRotor1(rotor1.getRingSetting());
+ state.setRingSettingRotor2(rotor2.getRingSetting());
+ state.setRingSettingRotor3(rotor3.getRingSetting());
+
+ state.setTypeReflector(reflector.getIndex());
+ state.setRotationReflector(reflector.getRotation());
+ state.setRingSettingReflector(reflector.getRingSetting());
+
+ return state;
+ }
+
+ @Override
+ public void restoreState(BigInteger s, int protocol_version)
+ {
+ switch (protocol_version)
+ {
+ case 1:
+ int r1 = getValue(s,availableRotors.size());
+ s = removeDigit(s,availableRotors.size());
+ int r2 = getValue(s,availableRotors.size());
+ s = removeDigit(s,availableRotors.size());
+ int r3 = getValue(s,availableRotors.size());
+ s = removeDigit(s,availableRotors.size());
+
+ int rot1 = getValue(s,26);
+ s = removeDigit(s,26);
+ int ring1 = getValue(s,26);
+ s = removeDigit(s,26);
+ int rot2 = getValue(s,26);
+ s = removeDigit(s,26);
+ int ring2 = getValue(s,26);
+ s = removeDigit(s,26);
+ int rot3 = getValue(s,26);
+ s = removeDigit(s,26);
+ int ring3 = getValue(s,26);
+ s = removeDigit(s,26);
+ int rotRef = getValue(s,26);
+ s = removeDigit(s,26);
+ int ringRef = getValue(s,26);
+
+ this.entryWheel = getEntryWheel(0);
+ this.rotor1 = getRotor(r1, rot1, ring1);
+ this.rotor2 = getRotor(r2, rot2, ring2);
+ this.rotor3 = getRotor(r3, rot3, ring3);
+ this.reflector = getReflector(0, rotRef, ringRef);
+ break;
+
+ default: Log.e(MainActivity.APP_ID, "Unsupported protocol version "+protocol_version);
+ }
+ }
+
+ @Override
+ public BigInteger getEncodedState(int protocol_version)
+ {
+ BigInteger s = BigInteger.valueOf(reflector.getRingSetting());
+ s = addDigit(s, reflector.getRotation(), 26);
+ s = addDigit(s, rotor3.getRingSetting(),26);
+ s = addDigit(s, rotor3.getRotation(), 26);
+ s = addDigit(s, rotor2.getRingSetting(),26);
+ s = addDigit(s, rotor2.getRotation(), 26);
+ s = addDigit(s, rotor1.getRingSetting(), 26);
+ s = addDigit(s, rotor1.getRotation(), 26);
+
+ s = addDigit(s, rotor3.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor2.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor1.getIndex(), availableRotors.size());
+
+ s = addDigit(s, 7, 20); //Machine #7
+ s = addDigit(s, protocol_version, MainActivity.max_protocol_version);
+
+ return s;
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_KD.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_KD.java
new file mode 100644
index 0000000..c751069
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_KD.java
@@ -0,0 +1,240 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.enigma;
+
+import android.util.Log;
+
+import java.math.BigInteger;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.enigma.parts.EntryWheel;
+import de.vanitasvitae.enigmandroid.enigma.parts.Plugboard;
+import de.vanitasvitae.enigmandroid.enigma.parts.Reflector;
+import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
+
+/**
+ * Concrete implementation of an enigma machine of name D
+ * This machine has a rewirable UKW, non changeable rotors.
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class Enigma_KD extends Enigma {
+
+ private EntryWheel entryWheel;
+ private Rotor rotor1;
+ private Rotor rotor2;
+ private Rotor rotor3;
+ private Reflector reflector;
+
+ public Enigma_KD()
+ {
+ super();
+ machineType = "KD";
+ Log.d(MainActivity.APP_ID, "Created Enigma KD");
+ }
+
+ @Override
+ protected void establishAvailableParts()
+ {
+ addAvailableEntryWheel(new EntryWheel.EntryWheel_QWERTZ());
+
+ addAvailableRotor(new Rotor.Rotor_KD_I(0, 0));
+ addAvailableRotor(new Rotor.Rotor_KD_II(0, 0));
+ addAvailableRotor(new Rotor.Rotor_KD_III(0, 0));
+
+ addAvailableReflector(new Reflector.ReflectorEnigma_KD());
+ }
+
+ @Override
+ public void initialize()
+ {
+ this.entryWheel = availableEntryWheels.get(0);
+ this.rotor1 = availableRotors.get(0);
+ this.rotor2 = availableRotors.get(1);
+ this.rotor3 = availableRotors.get(2);
+ this.reflector = availableReflectors.get(0);
+ }
+
+ @Override
+ public void nextState()
+ {
+ rotor1.rotate();
+ if (rotor1.isAtTurnoverPosition() || this.doAnomaly)
+ {
+ rotor2.rotate();
+ this.doAnomaly = rotor2.doubleTurnAnomaly();
+ if (rotor2.isAtTurnoverPosition())
+ {
+ rotor3.rotate();
+ }
+ }
+ }
+
+ @Override
+ protected void generateState() {
+ int r1, r2=-1, r3;
+ r1 = rand.nextInt(3);
+ while(r2 == -1 || r2 == r1) r2 = rand.nextInt(3);
+ r3 = 3 - r1 - r2;
+
+ int rot1 = rand.nextInt(26);
+ int rot2 = rand.nextInt(26);
+ int rot3 = rand.nextInt(26);
+ int rotRef = rand.nextInt(26);
+ int ring1 = rand.nextInt(26);
+ int ring2 = rand.nextInt(26);
+ int ring3 = rand.nextInt(26);
+ int ringRef = rand.nextInt(26);
+
+ this.entryWheel = getEntryWheel(0);
+ this.rotor1 = getRotor(r1, rot1, ring1);
+ this.rotor2 = getRotor(r2, rot2, ring2);
+ this.rotor3 = getRotor(r3, rot3, ring3);
+ this.reflector = getReflector(0, rotRef, ringRef);
+ this.reflector.setRotation(rotRef).setRingSetting(ringRef)
+ .setConfiguration(Plugboard.seedToReflectorConfiguration(rand));
+ }
+
+ @Override
+ public char encryptChar(char k)
+ {
+ nextState();
+ int x = ((int) k)-65; //Cast to int and remove Unicode Offset (A=65 in Unicode.)
+ //Encryption
+ //forward direction
+ x = entryWheel.encryptForward(x);
+ x = rotor1.normalize(x + rotor1.getRotation() - rotor1.getRingSetting());
+ x = rotor1.encryptForward(x);
+ x = rotor1.normalize(x - rotor1.getRotation() + rotor1.getRingSetting() + rotor2.getRotation() - rotor2.getRingSetting());
+ x = rotor2.encryptForward(x);
+ x = rotor1.normalize(x - rotor2.getRotation() + rotor2.getRingSetting() + rotor3.getRotation() - rotor3.getRingSetting());
+ x = rotor3.encryptForward(x);
+ x = rotor1.normalize(x - rotor3.getRotation() + rotor3.getRingSetting() + reflector.getRotation() - reflector.getRingSetting());
+ //backward direction
+ x = reflector.encrypt(x);
+ x = rotor1.normalize(x + rotor3.getRotation() - rotor3.getRingSetting() - reflector.getRotation() + reflector.getRingSetting());
+ x = rotor3.encryptBackward(x);
+ x = rotor1.normalize(x + rotor2.getRotation() - rotor2.getRingSetting() - rotor3.getRotation() + rotor3.getRingSetting());
+ x = rotor2.encryptBackward(x);
+ x = rotor1.normalize(x + rotor1.getRotation() - rotor1.getRingSetting() - rotor2.getRotation() + rotor2.getRingSetting());
+ x = rotor1.encryptBackward(x);
+ x = rotor1.normalize(x - rotor1.getRotation() + rotor1.getRingSetting());
+ x = entryWheel.encryptBackward(x);
+ return (char) (x + 65); //Add Offset again, cast back to char and return
+ }
+
+ @Override
+ public void setState(EnigmaStateBundle state)
+ {
+ this.entryWheel = getEntryWheel(state.getTypeEntryWheel());
+ this.rotor1 = getRotor(state.getTypeRotor1(), state.getRotationRotor1(), state.getRingSettingRotor1());
+ this.rotor2 = getRotor(state.getTypeRotor2(), state.getRotationRotor2(), state.getRingSettingRotor2());
+ this.rotor3 = getRotor(state.getTypeRotor3(), state.getRotationRotor3(), state.getRingSettingRotor3());
+ this.reflector = getReflector(state.getTypeReflector(),
+ state.getRotationReflector(),
+ state.getRingSettingReflector())
+ .setConfiguration(state.getConfigurationReflector());
+ }
+
+ @Override
+ public EnigmaStateBundle getState()
+ {
+ EnigmaStateBundle state = new EnigmaStateBundle();
+
+ state.setTypeEntryWheel(entryWheel.getIndex());
+
+ state.setTypeRotor1(rotor1.getIndex());
+ state.setTypeRotor2(rotor2.getIndex());
+ state.setTypeRotor3(rotor3.getIndex());
+
+ state.setRotationRotor1(rotor1.getRotation());
+ state.setRotationRotor2(rotor2.getRotation());
+ state.setRotationRotor3(rotor3.getRotation());
+
+ state.setRingSettingRotor1(rotor1.getRingSetting());
+ state.setRingSettingRotor2(rotor2.getRingSetting());
+ state.setRingSettingRotor3(rotor3.getRingSetting());
+
+ state.setTypeReflector(reflector.getIndex());
+ state.setRotationReflector(reflector.getRotation());
+ state.setRingSettingReflector(reflector.getRingSetting());
+ state.setConfigurationReflector(reflector.getConfiguration());
+
+ return state;
+ }
+
+ @Override
+ public void restoreState(BigInteger s, int protocol_version)
+ {
+ switch (protocol_version)
+ {
+ case 1:
+ int r1 = getValue(s, availableRotors.size());
+ s = removeDigit(s, availableRotors.size());
+ int r2 = getValue(s, availableRotors.size());
+ s = removeDigit(s, availableRotors.size());
+ int r3 = getValue(s, availableRotors.size());
+ s = removeDigit(s, availableRotors.size());
+
+ int rot1 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int ring1 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int rot2 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int ring2 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int rot3 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int ring3 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int rotRef = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int ringRef = getValue(s, 26);
+ s = removeDigit(s, 26);
+
+ this.rotor1 = getRotor(r1, rot1, ring1);
+ this.rotor2 = getRotor(r2, rot2, ring2);
+ this.rotor3 = getRotor(r3, rot3, ring3);
+ this.reflector = getReflector(0, rotRef, ringRef);
+ this.reflector.setConfiguration(s);
+ break;
+
+ default: Log.e(MainActivity.APP_ID, "Unsupported protocol version "+protocol_version);
+ }
+
+ }
+
+ @Override
+ public BigInteger getEncodedState(int protocol_version) {
+ BigInteger s = Plugboard.configurationToBigInteger(reflector.getConfiguration());
+ s = addDigit(s, reflector.getRingSetting(), 26);
+ s = addDigit(s, reflector.getRotation(), 26);
+ s = addDigit(s, rotor3.getRingSetting(), 26);
+ s = addDigit(s, rotor3.getRotation(), 26);
+ s = addDigit(s, rotor2.getRingSetting(), 26);
+ s = addDigit(s, rotor2.getRotation(), 26);
+ s = addDigit(s, rotor1.getRingSetting(), 26);
+ s = addDigit(s, rotor1.getRotation(), 26);
+
+ s = addDigit(s, rotor3.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor2.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor1.getIndex(), availableRotors.size());
+
+ s = addDigit(s, 12, 20); //Machine #12
+ s = addDigit(s, protocol_version, MainActivity.max_protocol_version);
+
+ return s;
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_K_Swiss_Airforce.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_K_Swiss_Airforce.java
new file mode 100644
index 0000000..830999b
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_K_Swiss_Airforce.java
@@ -0,0 +1,70 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.enigma;
+
+import android.util.Log;
+
+import java.math.BigInteger;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.enigma.parts.EntryWheel;
+import de.vanitasvitae.enigmandroid.enigma.parts.Reflector;
+import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
+
+/**
+ * Implementation of the Enigma machine of name K (Switzerland, Airforce)
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class Enigma_K_Swiss_Airforce extends Enigma_K
+{
+ public Enigma_K_Swiss_Airforce()
+ {
+ super();
+ machineType = "KSA";
+ Log.d(MainActivity.APP_ID, "Created Enigma KSA");
+ }
+
+ @Override
+ protected void establishAvailableParts()
+ {
+ addAvailableEntryWheel(new EntryWheel.EntryWheel_QWERTZ());
+ addAvailableRotor(new Rotor.Rotor_K_Swiss_Airforce_I(0,0));
+ addAvailableRotor(new Rotor.Rotor_K_Swiss_Airforce_II(0,0));
+ addAvailableRotor(new Rotor.Rotor_K_Swiss_Airforce_III(0,0));
+ addAvailableReflector(new Reflector.Reflector_K_G260());
+ }
+
+ @Override
+ public BigInteger getEncodedState(int protocol_version)
+ {
+ BigInteger s = BigInteger.valueOf(reflector.getRingSetting());
+ s = addDigit(s, reflector.getRotation(), 26);
+ s = addDigit(s, rotor3.getRingSetting(),26);
+ s = addDigit(s, rotor3.getRotation(), 26);
+ s = addDigit(s, rotor2.getRingSetting(),26);
+ s = addDigit(s, rotor2.getRotation(), 26);
+ s = addDigit(s, rotor1.getRingSetting(), 26);
+ s = addDigit(s, rotor1.getRotation(), 26);
+
+ s = addDigit(s, rotor3.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor2.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor1.getIndex(), availableRotors.size());
+
+ s = addDigit(s, 9, 20); //Machine #9
+ s = addDigit(s, protocol_version, MainActivity.max_protocol_version);
+
+ return s;
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_K_Swiss_Standard.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_K_Swiss_Standard.java
new file mode 100644
index 0000000..6707c15
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_K_Swiss_Standard.java
@@ -0,0 +1,71 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.enigma;
+
+import android.util.Log;
+
+import java.math.BigInteger;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.enigma.parts.EntryWheel;
+import de.vanitasvitae.enigmandroid.enigma.parts.Reflector;
+import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
+
+/**
+ * Implementation of the Enigma machine of name K (Switzerland)
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class Enigma_K_Swiss_Standard extends Enigma_K
+{
+ public Enigma_K_Swiss_Standard()
+ {
+ super();
+ machineType = "KS";
+ Log.d(MainActivity.APP_ID, "Created Enigma KS");
+ }
+
+ @Override
+ protected void establishAvailableParts()
+ {
+ addAvailableEntryWheel(new EntryWheel.EntryWheel_QWERTZ());
+ addAvailableRotor(new Rotor.Rotor_KSwiss_Standard_I(0,0));
+ addAvailableRotor(new Rotor.Rotor_KSwiss_Standard_II(0,0));
+ addAvailableRotor(new Rotor.Rotor_KSwiss_Standard_III(0,0));
+ addAvailableReflector(new Reflector.Reflector_K_G260());
+ }
+
+ @Override
+ public BigInteger getEncodedState(int protocol_version)
+ {
+ BigInteger s = BigInteger.valueOf(reflector.getRingSetting());
+ s = addDigit(s, reflector.getRotation(), 26);
+ s = addDigit(s, rotor3.getRingSetting(),26);
+ s = addDigit(s, rotor3.getRotation(), 26);
+ s = addDigit(s, rotor2.getRingSetting(),26);
+ s = addDigit(s, rotor2.getRotation(), 26);
+ s = addDigit(s, rotor1.getRingSetting(), 26);
+ s = addDigit(s, rotor1.getRotation(), 26);
+
+ s = addDigit(s, rotor3.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor2.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor1.getIndex(), availableRotors.size());
+
+ s = addDigit(s, 8, 20); //Machine #8
+ s = addDigit(s, protocol_version, MainActivity.max_protocol_version);
+
+ return s;
+ }
+
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_M3.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_M3.java
new file mode 100644
index 0000000..ed07d42
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_M3.java
@@ -0,0 +1,99 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.enigma;
+
+import android.util.Log;
+
+import java.math.BigInteger;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.enigma.parts.EntryWheel;
+import de.vanitasvitae.enigmandroid.enigma.parts.Plugboard;
+import de.vanitasvitae.enigmandroid.enigma.parts.Reflector;
+import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
+
+/**
+ * Concrete implementation of an enigma machine model M3
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class Enigma_M3 extends Enigma_I
+{
+ public Enigma_M3()
+ {
+ super();
+ machineType = "M3";
+ Log.d(MainActivity.APP_ID, "Created Enigma M3");
+ }
+
+ @Override
+ protected void establishAvailableParts()
+ {
+ addAvailableEntryWheel(new EntryWheel.EntryWheel_ABCDEF());
+ addAvailableRotor(new Rotor.Rotor_I(0, 0));
+ addAvailableRotor(new Rotor.Rotor_II(0,0));
+ addAvailableRotor(new Rotor.Rotor_III(0,0));
+ addAvailableRotor(new Rotor.Rotor_IV(0,0));
+ addAvailableRotor(new Rotor.Rotor_V(0,0));
+ addAvailableRotor(new Rotor.Rotor_VI(0,0));
+ addAvailableRotor(new Rotor.Rotor_VII(0,0));
+ addAvailableRotor(new Rotor.Rotor_VIII(0,0));
+ addAvailableReflector(new Reflector.Reflector_B());
+ addAvailableReflector(new Reflector.Reflector_C());
+ }
+
+ @Override
+ protected void generateState() {
+ int r1, r2=-1, r3=-1;
+ r1 = rand.nextInt(8);
+ while(r2 == -1 || r2 == r1) r2 = rand.nextInt(8);
+ while(r3 == -1 || r3 == r2 || r3 == r1) r3 = rand.nextInt(8);
+ int ref = rand.nextInt(2);
+
+ int rot1 = rand.nextInt(26);
+ int rot2 = rand.nextInt(26);
+ int rot3 = rand.nextInt(26);
+ int ring1 = rand.nextInt(26);
+ int ring2 = rand.nextInt(26);
+ int ring3 = rand.nextInt(26);
+
+ this.entryWheel = getEntryWheel(0);
+ this.rotor1 = getRotor(r1, rot1, ring1);
+ this.rotor2 = getRotor(r2, rot2, ring2);
+ this.rotor3 = getRotor(r3, rot3, ring3);
+ this.reflector = getReflector(ref);
+
+ this.plugboard = new Plugboard();
+ plugboard.setConfiguration(Plugboard.seedToPlugboardConfiguration(rand));
+ }
+
+ @Override
+ public BigInteger getEncodedState(int protocol_version) {
+ BigInteger s = Plugboard.configurationToBigInteger(plugboard.getConfiguration());
+ s = addDigit(s, rotor3.getRingSetting(), 26);
+ s = addDigit(s, rotor3.getRotation(), 26);
+ s = addDigit(s, rotor2.getRingSetting(), 26);
+ s = addDigit(s, rotor2.getRotation(), 26);
+ s = addDigit(s, rotor1.getRingSetting(), 26);
+ s = addDigit(s, rotor1.getRotation(), 26);
+ s = addDigit(s, reflector.getIndex(), availableReflectors.size());
+ s = addDigit(s, rotor3.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor2.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor1.getIndex(), availableRotors.size());
+ s = addDigit(s, 1, 20); //Machine #1
+ s = addDigit(s, protocol_version, MainActivity.max_protocol_version);
+
+ return s;
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_M4.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_M4.java
new file mode 100644
index 0000000..29e160a
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_M4.java
@@ -0,0 +1,320 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.enigma;
+
+import android.util.Log;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.enigma.parts.EntryWheel;
+import de.vanitasvitae.enigmandroid.enigma.parts.Plugboard;
+import de.vanitasvitae.enigmandroid.enigma.parts.Reflector;
+import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
+
+/**
+ * Concrete Implementation of the Enigma Machine name M4 of the german Kriegsmarine
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class Enigma_M4 extends Enigma
+{
+ private ArrayList availableThinRotors;
+ private EntryWheel entryWheel;
+ private Rotor rotor1;
+ private Rotor rotor2;
+ private Rotor rotor3;
+
+ private Rotor rotor4;
+
+ private Reflector reflector;
+
+ private Plugboard plugboard;
+
+ public Enigma_M4()
+ {
+ super();
+ machineType = "M4";
+ Log.d(MainActivity.APP_ID, "Created Enigma M4");
+ }
+
+ private void addAvailableThinRotor(Rotor r)
+ {
+ if(availableThinRotors == null) availableThinRotors = new ArrayList<>();
+ availableThinRotors.add(availableThinRotors.size(), r.setIndex(availableThinRotors.size()));
+ }
+
+ private Rotor getThinRotor(int index)
+ {
+ if(availableThinRotors == null || availableThinRotors.size() == 0) return null;
+ return availableThinRotors.get(index % availableThinRotors.size()).getInstance();
+ }
+
+ private Rotor getThinRotor(int index, int rotation, int ringSettings)
+ {
+ Rotor r = getThinRotor(index);
+ if(r == null) return null;
+ return r.setRotation(rotation).setRingSetting(ringSettings);
+ }
+
+ @Override
+ protected void establishAvailableParts()
+ {
+ Log.d(MainActivity.APP_ID, "Established");
+ addAvailableEntryWheel(new EntryWheel.EntryWheel_ABCDEF());
+ addAvailableRotor(new Rotor.Rotor_I(0, 0));
+ addAvailableRotor(new Rotor.Rotor_II(0,0));
+ addAvailableRotor(new Rotor.Rotor_III(0,0));
+ addAvailableRotor(new Rotor.Rotor_IV(0,0));
+ addAvailableRotor(new Rotor.Rotor_V(0,0));
+ addAvailableRotor(new Rotor.Rotor_VI(0,0));
+ addAvailableRotor(new Rotor.Rotor_VII(0, 0));
+ addAvailableRotor(new Rotor.Rotor_VIII(0,0));
+ addAvailableThinRotor(new Rotor.Rotor_M4_Beta(0, 0));
+ addAvailableThinRotor(new Rotor.Rotor_M4_Gamma(0, 0));
+ addAvailableReflector(new Reflector.Reflector_Thin_B());
+ addAvailableReflector(new Reflector.ReflectorThinC());
+ }
+
+ @Override
+ public void initialize()
+ {
+ Log.d(MainActivity.APP_ID, "Initialized");
+ this.plugboard = new Plugboard();
+ this.entryWheel = getEntryWheel(0);
+ this.rotor1 = getRotor(0, 0, 0);
+ this.rotor2 = getRotor(1, 0, 0);
+ this.rotor3 = getRotor(2, 0, 0);
+ this.rotor4 = getThinRotor(0, 0, 0);
+ this.reflector = getReflector(0);
+ }
+
+ @Override
+ /**
+ * Set the enigma into the next mechanical state.
+ * This rotates the first rotor and eventually also the second/third.
+ * Also this method handles the anomaly in case it should happen.
+ */
+ public void nextState()
+ {
+ //Rotate rotors
+ rotor1.rotate();
+ //Eventually turn next rotor (usual turnOver or anomaly)
+ if (rotor1.isAtTurnoverPosition() || this.doAnomaly)
+ {
+ rotor2.rotate();
+ //Set doAnomaly for next call of encryptChar
+ this.doAnomaly = rotor2.doubleTurnAnomaly();
+ //Eventually rotate next rotor
+ if (rotor2.isAtTurnoverPosition())
+ {
+ rotor3.rotate();
+ }
+ }
+ }
+
+ @Override
+ protected void generateState() {
+ int r1, r2=-1, r3=-1;
+ int r4;
+ int ref;
+ r1 = rand.nextInt(8);
+ while(r2 == -1 || r2 == r1) r2 = rand.nextInt(8);
+ while(r3 == -1 || r3 == r2 || r3 == r1) r3 = rand.nextInt(8);
+ r4 = rand.nextInt(2);
+ ref = rand.nextInt(2);
+
+ int rot1 = rand.nextInt(26);
+ int rot2 = rand.nextInt(26);
+ int rot3 = rand.nextInt(26);
+ int rot4 = rand.nextInt(26);
+ int rotRef = rand.nextInt(26);
+ int ring1 = rand.nextInt(26);
+ int ring2 = rand.nextInt(26);
+ int ring3 = rand.nextInt(26);
+ int ring4 = rand.nextInt(26);
+ int ringRef = rand.nextInt(26);
+
+ this.entryWheel = getEntryWheel(0);
+ this.rotor1 = getRotor(r1, rot1, ring1);
+ this.rotor2 = getRotor(r2, rot2, ring2);
+ this.rotor3 = getRotor(r3, rot3, ring3);
+ this.rotor4 = getThinRotor(r4, rot4, ring4);
+
+ this.reflector = getReflector(ref, rotRef, ringRef);
+
+ this.plugboard = new Plugboard();
+ this.plugboard.setConfiguration(Plugboard.seedToPlugboardConfiguration(rand));
+ }
+
+ @Override
+ /**
+ * Substitute char k by sending the signal through the enigma.
+ * The signal passes the plugboard, the rotors and returns back after going through the
+ * reflector wheel.
+ *
+ * @param k input char
+ * @return substituted output char
+ */
+ public char encryptChar(char k)
+ {
+ nextState(); //Rotate rotors
+ int x = ((int) k)-65; //Cast to int and remove Unicode Offset (A=65 in Unicode.)
+ //Encryption
+ //forward direction
+ x = plugboard.encrypt(x);
+ x = entryWheel.encryptForward(x);
+ x = rotor1.normalize(x + rotor1.getRotation() - rotor1.getRingSetting());
+ x = rotor1.encryptForward(x);
+ x = rotor1.normalize(x - rotor1.getRotation() + rotor1.getRingSetting() + rotor2.getRotation() - rotor2.getRingSetting());
+ x = rotor2.encryptForward(x);
+ x = rotor1.normalize(x - rotor2.getRotation() + rotor2.getRingSetting() + rotor3.getRotation() - rotor3.getRingSetting());
+ x = rotor3.encryptForward(x);
+ x = rotor1.normalize(x - rotor3.getRotation() + rotor3.getRingSetting() + rotor4.getRotation() - rotor4.getRingSetting());
+ x = rotor4.encryptForward(x);
+ x = rotor1.normalize(x - rotor4.getRotation() + rotor4.getRingSetting());
+ //backward direction
+ x = reflector.encrypt(x);
+ x = rotor1.normalize(x + rotor4.getRotation() - rotor4.getRingSetting());
+ x = rotor4.encryptBackward(x);
+ x = rotor1.normalize(x + rotor3.getRotation() - rotor3.getRingSetting() - rotor4.getRotation() + rotor4.getRingSetting());
+ x = rotor3.encryptBackward(x);
+ x = rotor1.normalize(x + rotor2.getRotation() - rotor2.getRingSetting() - rotor3.getRotation() + rotor3.getRingSetting());
+ x = rotor2.encryptBackward(x);
+ x = rotor1.normalize(x + rotor1.getRotation() - rotor1.getRingSetting() - rotor2.getRotation() + rotor2.getRingSetting());
+ x = rotor1.encryptBackward(x);
+ x = rotor1.normalize(x - rotor1.getRotation() + rotor1.getRingSetting());
+ x = entryWheel.encryptBackward(x);
+ x = plugboard.encrypt(x);
+ return (char) (x + 65); //Add Offset again and cast back to char
+ }
+
+ @Override
+ public void setState(EnigmaStateBundle state)
+ {
+ rotor1 = getRotor(state.getTypeRotor1(), state.getRotationRotor1(), state.getRingSettingRotor1());
+ rotor2 = getRotor(state.getTypeRotor2(), state.getRotationRotor2(), state.getRingSettingRotor2());
+ rotor3 = getRotor(state.getTypeRotor3(), state.getRotationRotor3(), state.getRingSettingRotor3());
+ rotor4 = getThinRotor(state.getTypeRotor4(), state.getRotationRotor4(), state.getRingSettingRotor4());
+ reflector = getReflector(state.getTypeReflector());
+ plugboard.setConfiguration(state.getConfigurationPlugboard());
+
+ }
+
+ @Override
+ public EnigmaStateBundle getState()
+ {
+ EnigmaStateBundle state = new EnigmaStateBundle();
+ state.setTypeEntryWheel(entryWheel.getIndex());
+
+ state.setTypeRotor1(rotor1.getIndex());
+ state.setTypeRotor2(rotor2.getIndex());
+ state.setTypeRotor3(rotor3.getIndex());
+ state.setTypeRotor4(rotor4.getIndex());
+
+ state.setRotationRotor1(rotor1.getRotation());
+ state.setRotationRotor2(rotor2.getRotation());
+ state.setRotationRotor3(rotor3.getRotation());
+ state.setRotationRotor4(rotor4.getRotation());
+
+ state.setRingSettingRotor1(rotor1.getRingSetting());
+ state.setRingSettingRotor2(rotor2.getRingSetting());
+ state.setRingSettingRotor3(rotor3.getRingSetting());
+ state.setRingSettingRotor4(rotor4.getRingSetting());
+
+ state.setTypeReflector(reflector.getIndex());
+
+ state.setConfigurationPlugboard(plugboard.getConfiguration());
+
+ return state;
+ }
+
+ @Override
+ public void restoreState(BigInteger s, int protocol_version)
+ {
+ switch (protocol_version)
+ {
+ case 1:
+ int r1 = getValue(s, availableRotors.size());
+ s = removeDigit(s, availableRotors.size());
+ int r2 = getValue(s, availableRotors.size());
+ s = removeDigit(s,availableRotors.size());
+ int r3 = getValue(s, availableRotors.size());
+ s = removeDigit(s,availableRotors.size());
+ int r4 = getValue(s, availableThinRotors.size());
+ s = removeDigit(s,availableThinRotors.size());
+ int ref = getValue(s, availableReflectors.size());
+ s = removeDigit(s,availableReflectors.size());
+
+ int rot1 = getValue(s, 26);
+ s = removeDigit(s,26);
+ int ring1 = getValue(s, 26);
+ s = removeDigit(s,26);
+ int rot2 = getValue(s, 26);
+ s = removeDigit(s,26);
+ int ring2 = getValue(s, 26);
+ s = removeDigit(s,26);
+ int rot3 = getValue(s, 26);
+ s = removeDigit(s,26);
+ int ring3 = getValue(s, 26);
+ s = removeDigit(s,26);
+ int rot4 = getValue(s, 26);
+ s = removeDigit(s,26);
+ int ring4 = getValue(s, 26);
+ s = removeDigit(s,26);
+ int rotRef = getValue(s, 26);
+ s = removeDigit(s,26);
+ int ringRef = getValue(s, 26);
+ s = removeDigit(s, 26);
+
+ this.rotor1 = getRotor(r1, rot1, ring1);
+ this.rotor2 = getRotor(r2, rot2, ring2);
+ this.rotor3 = getRotor(r3, rot3, ring3);
+ this.rotor4 = getThinRotor(r4, rot4, ring4);
+ this.reflector = getReflector(ref, rotRef, ringRef);
+ this.plugboard = new Plugboard();
+ plugboard.setConfiguration(s);
+ break;
+
+ default: Log.e(MainActivity.APP_ID, "Unsupported protocol version "+protocol_version);
+ }
+ }
+
+ @Override
+ public BigInteger getEncodedState(int protocol_version) {
+ BigInteger s = Plugboard.configurationToBigInteger(plugboard.getConfiguration());
+ s = addDigit(s, reflector.getRingSetting(), 26);
+ s = addDigit(s, reflector.getRotation(), 26);
+ s = addDigit(s, rotor4.getRingSetting(), 26);
+ s = addDigit(s, rotor4.getRotation(), 26);
+ s = addDigit(s, rotor3.getRingSetting(), 26);
+ s = addDigit(s, rotor3.getRotation(), 26);
+ s = addDigit(s, rotor2.getRingSetting(), 26);
+ s = addDigit(s, rotor2.getRotation(), 26);
+ s = addDigit(s, rotor1.getRingSetting(), 26);
+ s = addDigit(s, rotor1.getRotation(), 26);
+
+ s = addDigit(s, reflector.getIndex(), availableReflectors.size());
+ s = addDigit(s, rotor4.getIndex(), availableThinRotors.size());
+ s = addDigit(s, rotor3.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor2.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor1.getIndex(), availableRotors.size());
+
+ s = addDigit(s, 2, 20);
+ s = addDigit(s, protocol_version, MainActivity.max_protocol_version);
+
+ return s;
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_R.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_R.java
new file mode 100644
index 0000000..028fce2
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_R.java
@@ -0,0 +1,231 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.enigma;
+
+import android.util.Log;
+
+import java.math.BigInteger;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.enigma.parts.EntryWheel;
+import de.vanitasvitae.enigmandroid.enigma.parts.Reflector;
+import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
+
+/**
+ * Implementation of the Enigma machine of name R ("Rocket", Reichsbahn)
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class Enigma_R extends Enigma
+{
+ private EntryWheel entryWheel;
+ private Rotor rotor1;
+ private Rotor rotor2;
+ private Rotor rotor3;
+
+ private Reflector reflector;
+
+ public Enigma_R()
+ {
+ super();
+ machineType = "R";
+ Log.d(MainActivity.APP_ID, "Created Enigma R");
+ }
+
+ @Override
+ protected void establishAvailableParts() {
+ addAvailableEntryWheel(new EntryWheel.EntryWheel_QWERTZ());
+ addAvailableRotor(new Rotor.Rotor_R_I(0, 0));
+ addAvailableRotor(new Rotor.Rotor_R_II(0,0));
+ addAvailableRotor(new Rotor.Rotor_R_III(0,0));
+ addAvailableReflector(new Reflector.Reflector_R());
+
+ }
+
+ @Override
+ public void initialize()
+ {
+ this.entryWheel = getEntryWheel(0);
+ this.rotor1 = getRotor(0);
+ this.rotor2 = getRotor(1);
+ this.rotor3 = getRotor(2);
+ this.reflector = getReflector(0);
+ }
+
+ @Override
+ public void nextState()
+ {
+ rotor1.rotate();
+ if (rotor1.isAtTurnoverPosition() || this.doAnomaly)
+ {
+ rotor2.rotate();
+ this.doAnomaly = rotor2.doubleTurnAnomaly();
+ if (rotor2.isAtTurnoverPosition())
+ {
+ rotor3.rotate();
+ }
+ }
+ }
+
+ @Override
+ protected void generateState()
+ {
+ int r1, r2=-1, r3;
+ r1 = rand.nextInt(3);
+ while(r2 == -1 || r2 == r1) r2 = rand.nextInt(3);
+ r3 = 3 - r1 - r2;
+
+ int rot1 = rand.nextInt(26);
+ int rot2 = rand.nextInt(26);
+ int rot3 = rand.nextInt(26);
+ int rotRef = rand.nextInt(26);
+ int ring1 = rand.nextInt(26);
+ int ring2 = rand.nextInt(26);
+ int ring3 = rand.nextInt(26);
+ int ringRef = rand.nextInt(26);
+
+ this.entryWheel = getEntryWheel(0);
+ this.rotor1 = getRotor(r1, rot1, ring1);
+ this.rotor2 = getRotor(r2, rot2, ring2);
+ this.rotor3 = getRotor(r3, rot3, ring3);
+ this.reflector = getReflector(0, rotRef, ringRef);
+ }
+
+ @Override
+ public char encryptChar(char k) {
+ nextState();
+ int x = ((int) k)-65; //Cast to int and remove Unicode Offset (A=65 in Unicode.)
+ //Encryption
+ //forward direction
+ x = entryWheel.encryptForward(x);
+ x = rotor1.normalize(x + rotor1.getRotation() - rotor1.getRingSetting());
+ x = rotor1.encryptForward(x);
+ x = rotor1.normalize(x - rotor1.getRotation() + rotor1.getRingSetting() + rotor2.getRotation() - rotor2.getRingSetting());
+ x = rotor2.encryptForward(x);
+ x = rotor1.normalize(x - rotor2.getRotation() + rotor2.getRingSetting() + rotor3.getRotation() - rotor3.getRingSetting());
+ x = rotor3.encryptForward(x);
+ x = rotor1.normalize(x - rotor3.getRotation() + rotor3.getRingSetting() + reflector.getRotation() - reflector.getRingSetting());
+ //backward direction
+ x = reflector.encrypt(x);
+ x = rotor1.normalize(x + rotor3.getRotation() - rotor3.getRingSetting() - reflector.getRotation() + reflector.getRingSetting());
+ x = rotor3.encryptBackward(x);
+ x = rotor1.normalize(x + rotor2.getRotation() - rotor2.getRingSetting() - rotor3.getRotation() + rotor3.getRingSetting());
+ x = rotor2.encryptBackward(x);
+ x = rotor1.normalize(x + rotor1.getRotation() - rotor1.getRingSetting() - rotor2.getRotation() + rotor2.getRingSetting());
+ x = rotor1.encryptBackward(x);
+ x = rotor1.normalize(x - rotor1.getRotation() + rotor1.getRingSetting());
+ x = entryWheel.encryptBackward(x);
+ return (char) (x + 65); //Add Offset again, cast back to char and return
+ }
+
+ @Override
+ public void setState(EnigmaStateBundle state)
+ {
+ this.entryWheel = getEntryWheel(state.getTypeEntryWheel());
+ this.rotor1 = getRotor(state.getTypeRotor1(), state.getRotationRotor1(), state.getRingSettingRotor1());
+ this.rotor2 = getRotor(state.getTypeRotor2(), state.getRotationRotor2(), state.getRingSettingRotor2());
+ this.rotor3 = getRotor(state.getTypeRotor3(), state.getRotationRotor3(), state.getRingSettingRotor3());
+ this.reflector = getReflector(state.getTypeReflector(), state.getRotationReflector(), state.getRingSettingReflector());
+ }
+
+ @Override
+ public EnigmaStateBundle getState() {
+ EnigmaStateBundle state = new EnigmaStateBundle();
+
+ state.setTypeEntryWheel(entryWheel.getIndex());
+
+ state.setTypeRotor1(rotor1.getIndex());
+ state.setTypeRotor2(rotor2.getIndex());
+ state.setTypeRotor3(rotor3.getIndex());
+
+ state.setRotationRotor1(rotor1.getRotation());
+ state.setRotationRotor2(rotor2.getRotation());
+ state.setRotationRotor3(rotor3.getRotation());
+
+ state.setRingSettingRotor1(rotor1.getRingSetting());
+ state.setRingSettingRotor2(rotor2.getRingSetting());
+ state.setRingSettingRotor3(rotor3.getRingSetting());
+
+ state.setTypeReflector(reflector.getIndex());
+ state.setRotationReflector(reflector.getRotation());
+ state.setRingSettingReflector(reflector.getRingSetting());
+
+ return state;
+ }
+
+ @Override
+ public void restoreState(BigInteger s, int protocol_version)
+ {
+ switch (protocol_version)
+ {
+ case 1:
+ int r1 = getValue(s,availableRotors.size());
+ s = removeDigit(s,availableRotors.size());
+ int r2 = getValue(s,availableRotors.size());
+ s = removeDigit(s,availableRotors.size());
+ int r3 = getValue(s,availableRotors.size());
+ s = removeDigit(s,availableRotors.size());
+
+ int rot1 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int ring1 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int rot2 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int ring2 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int rot3 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int ring3 = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int rotRef = getValue(s, 26);
+ s = removeDigit(s, 26);
+ int ringRef = getValue(s, 26);
+ s = removeDigit(s, 26);
+
+ this.entryWheel = getEntryWheel(0);
+ this.rotor1 = getRotor(r1, rot1, ring1);
+ this.rotor2 = getRotor(r2, rot2, ring2);
+ this.rotor3 = getRotor(r3, rot3, ring3);
+ this.reflector = getReflector(0, rotRef, ringRef);
+ break;
+
+ default: Log.e(MainActivity.APP_ID, "Unsupported protocol version "+protocol_version);
+ }
+
+ }
+
+ @Override
+ public BigInteger getEncodedState(int protocol_version)
+ {
+ BigInteger s = BigInteger.valueOf(reflector.getRingSetting());
+ s = addDigit(s, reflector.getRotation(), 26);
+
+ s = addDigit(s, rotor3.getRingSetting(),26);
+ s = addDigit(s, rotor3.getRotation(), 26);
+ s = addDigit(s, rotor2.getRingSetting(),26);
+ s = addDigit(s, rotor2.getRotation(), 26);
+ s = addDigit(s, rotor1.getRingSetting(), 26);
+ s = addDigit(s, rotor1.getRotation(), 26);
+
+ s = addDigit(s, rotor3.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor2.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor1.getIndex(), availableRotors.size());
+
+ s = addDigit(s, 10, 20); //Machine #10
+ s = addDigit(s, protocol_version, MainActivity.max_protocol_version);
+
+ return s;
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_T.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_T.java
new file mode 100644
index 0000000..aedc432
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_T.java
@@ -0,0 +1,228 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.enigma;
+
+import android.util.Log;
+
+import java.math.BigInteger;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.enigma.parts.EntryWheel;
+import de.vanitasvitae.enigmandroid.enigma.parts.Reflector;
+import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
+
+/**
+ * Implementation of the Enigma machine of name T Tirpitz
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class Enigma_T extends Enigma
+{
+ private EntryWheel entryWheel;
+ private Rotor rotor1;
+ private Rotor rotor2;
+ private Rotor rotor3;
+ private Reflector reflector;
+
+ public Enigma_T()
+ {
+ super();
+ machineType = "T";
+ Log.d(MainActivity.APP_ID, "Created Enigma T");
+ }
+
+ @Override
+ protected void establishAvailableParts() {
+ addAvailableEntryWheel(new EntryWheel.EntryWheel_T());
+ addAvailableRotor(new Rotor.Rotor_T_I(0, 0));
+ addAvailableRotor(new Rotor.Rotor_T_II(0,0));
+ addAvailableRotor(new Rotor.Rotor_T_III(0,0));
+ addAvailableRotor(new Rotor.Rotor_T_IV(0,0));
+ addAvailableRotor(new Rotor.Rotor_T_V(0,0));
+ addAvailableRotor(new Rotor.Rotor_T_VI(0,0));
+ addAvailableRotor(new Rotor.Rotor_T_VII(0,0));
+ addAvailableRotor(new Rotor.Rotor_T_VIII(0,0));
+ addAvailableReflector(new Reflector.ReflectorEnigma_T());
+ }
+
+ @Override
+ public void initialize() {
+ this.entryWheel = getEntryWheel(0);
+ this.rotor1 = getRotor(0);
+ this.rotor2 = getRotor(1);
+ this.rotor3 = getRotor(2);
+ this.reflector = getReflector(0);
+ }
+
+ @Override
+ public void nextState()
+ {
+ rotor1.rotate();
+ if (rotor1.isAtTurnoverPosition() || this.doAnomaly)
+ {
+ rotor2.rotate();
+ this.doAnomaly = rotor2.doubleTurnAnomaly();
+ if (rotor2.isAtTurnoverPosition())
+ {
+ rotor3.rotate();
+ }
+ }
+ }
+
+ @Override
+ protected void generateState() {
+ int r1, r2=-1, r3=-1;
+ r1 = rand.nextInt(8);
+ while(r2 == -1 || r2 == r1) r2 = rand.nextInt(8);
+ while(r3 == -1 || r3 == r2 || r3 == r1) r3 = rand.nextInt(8);
+
+ int rot1 = rand.nextInt(26);
+ int rot2 = rand.nextInt(26);
+ int rot3 = rand.nextInt(26);
+ int rotRef = rand.nextInt(26);
+ int ring1 = rand.nextInt(26);
+ int ring2 = rand.nextInt(26);
+ int ring3 = rand.nextInt(26);
+ int ringRef = rand.nextInt(26);
+
+ this.entryWheel = getEntryWheel(0);
+ this.rotor1 = getRotor(r1, rot1, ring1);
+ this.rotor2 = getRotor(r2, rot2, ring2);
+ this.rotor3 = getRotor(r3, rot3, ring3);
+ this.reflector = getReflector(0, rotRef, ringRef);
+ }
+
+ @Override
+ public char encryptChar(char k) {
+ nextState();
+ int x = ((int) k)-65; //Cast to int and remove Unicode Offset (A=65 in Unicode.)
+ //Encryption
+ //forward direction
+ x = entryWheel.encryptForward(x);
+ x = rotor1.normalize(x + rotor1.getRotation() - rotor1.getRingSetting());
+ x = rotor1.encryptForward(x);
+ x = rotor1.normalize(x - rotor1.getRotation() + rotor1.getRingSetting() + rotor2.getRotation() - rotor2.getRingSetting());
+ x = rotor2.encryptForward(x);
+ x = rotor1.normalize(x - rotor2.getRotation() + rotor2.getRingSetting() + rotor3.getRotation() - rotor3.getRingSetting());
+ x = rotor3.encryptForward(x);
+ x = rotor1.normalize(x - rotor3.getRotation() + rotor3.getRingSetting() + reflector.getRotation() - reflector.getRingSetting());
+ //backward direction
+ x = reflector.encrypt(x);
+ x = rotor1.normalize(x + rotor3.getRotation() - rotor3.getRingSetting() - reflector.getRotation() + reflector.getRingSetting());
+ x = rotor3.encryptBackward(x);
+ x = rotor1.normalize(x + rotor2.getRotation() - rotor2.getRingSetting() - rotor3.getRotation() + rotor3.getRingSetting());
+ x = rotor2.encryptBackward(x);
+ x = rotor1.normalize(x + rotor1.getRotation() - rotor1.getRingSetting() - rotor2.getRotation() + rotor2.getRingSetting());
+ x = rotor1.encryptBackward(x);
+ x = rotor1.normalize(x - rotor1.getRotation() + rotor1.getRingSetting());
+ x = entryWheel.encryptBackward(x);
+ return (char) (x + 65); //Add Offset again, cast back to char and return
+ }
+
+ @Override
+ public void setState(EnigmaStateBundle state) {
+ this.entryWheel = getEntryWheel(0);
+ this.rotor1 = getRotor(state.getTypeRotor1(), state.getRotationRotor1(), state.getRingSettingRotor1());
+ this.rotor2 = getRotor(state.getTypeRotor2(), state.getRotationRotor2(), state.getRingSettingRotor2());
+ this.rotor3 = getRotor(state.getTypeRotor3(), state.getRotationRotor3(), state.getRingSettingRotor3());
+ this.reflector = getReflector(state.getTypeReflector(), state.getRotationReflector(), state.getRingSettingReflector());
+ }
+
+ @Override
+ public EnigmaStateBundle getState()
+ {
+ EnigmaStateBundle state = new EnigmaStateBundle();
+
+ state.setTypeRotor1(rotor1.getIndex());
+ state.setTypeRotor2(rotor2.getIndex());
+ state.setTypeRotor3(rotor3.getIndex());
+
+ state.setRotationRotor1(rotor1.getRotation());
+ state.setRotationRotor2(rotor2.getRotation());
+ state.setRotationRotor3(rotor3.getRotation());
+
+ state.setRingSettingRotor1(rotor1.getRingSetting());
+ state.setRingSettingRotor2(rotor2.getRingSetting());
+ state.setRingSettingRotor3(rotor3.getRingSetting());
+
+ state.setTypeReflector(reflector.getIndex());
+ state.setRotationReflector(reflector.getRotation());
+ state.setRingSettingReflector(reflector.getRingSetting());
+ state.setTypeEntryWheel(entryWheel.getIndex());
+
+ return state;
+ }
+
+ @Override
+ public void restoreState(BigInteger s, int protocol_version)
+ {
+ switch (protocol_version)
+ {
+ case 1:
+ int r1 = getValue(s,availableRotors.size());
+ s = removeDigit(s,availableRotors.size());
+ int r2 = getValue(s,availableRotors.size());
+ s = removeDigit(s,availableRotors.size());
+ int r3 = getValue(s,availableRotors.size());
+ s = removeDigit(s,availableRotors.size());
+
+ int rot1 = getValue(s,26);
+ s = removeDigit(s,26);
+ int ring1 = getValue(s,26);
+ s = removeDigit(s,26);
+ int rot2 = getValue(s,26);
+ s = removeDigit(s,26);
+ int ring2 = getValue(s,26);
+ s = removeDigit(s,26);
+ int rot3 = getValue(s,26);
+ s = removeDigit(s,26);
+ int ring3 = getValue(s,26);
+ s = removeDigit(s,26);
+ int rotRef = getValue(s,26);
+ s = removeDigit(s, 26);
+ int ringRef = getValue(s,26);
+
+ this.rotor1 = getRotor(r1, rot1, ring1);
+ this.rotor2 = getRotor(r2, rot2, ring2);
+ this.rotor3 = getRotor(r3, rot3, ring3);
+ this.reflector = getReflector(0, rotRef, ringRef);
+ break;
+
+ default: Log.e(MainActivity.APP_ID, "Unsupported protocol version "+protocol_version);
+ }
+
+ }
+
+ @Override
+ public BigInteger getEncodedState(int protocol_version)
+ {
+ BigInteger s = BigInteger.valueOf(reflector.getRingSetting());
+ s = addDigit(s, reflector.getRotation(), 26);
+ s = addDigit(s, rotor3.getRingSetting(),26);
+ s = addDigit(s, rotor3.getRotation(), 26);
+ s = addDigit(s, rotor2.getRingSetting(),26);
+ s = addDigit(s, rotor2.getRotation(), 26);
+ s = addDigit(s, rotor1.getRingSetting(), 26);
+ s = addDigit(s, rotor1.getRotation(), 26);
+
+ s = addDigit(s, rotor3.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor2.getIndex(), availableRotors.size());
+ s = addDigit(s, rotor1.getIndex(), availableRotors.size());
+
+ s = addDigit(s, 11, 20); //Machine #11
+ s = addDigit(s, protocol_version, MainActivity.max_protocol_version);
+
+ return s;
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/inputPreparer/EditTextAdapter.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/inputPreparer/EditTextAdapter.java
new file mode 100644
index 0000000..9b634b2
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/inputPreparer/EditTextAdapter.java
@@ -0,0 +1,119 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.enigma.inputPreparer;
+
+import android.widget.EditText;
+
+/**
+ * Adapter-like connector between text fields and string-outputting-whatever blah
+ * Use this to modify the way strings get displayed without modifying the string itself.
+ */
+public abstract class EditTextAdapter
+{
+ EditText editText;
+ String content;
+
+ EditTextAdapter(EditText editText)
+ {
+ this.editText = editText;
+ }
+
+ /**
+ * Returns the unmodified text
+ * @return content
+ */
+ public String getText()
+ {
+ if(editText.getText().length() != 0)
+ return content;
+ else return content = "";
+ }
+
+ public String getModifiedText()
+ {
+ return editText.getText().toString();
+ }
+
+ /**
+ * Set the text to both the content and the editText without modifying it
+ * @param text text
+ */
+ public void setRawText(String text)
+ {
+ this.content = text;
+ this.editText.setText(text);
+ }
+
+ /**
+ * This method needs to be overwritten by the programmer.
+ * The coder has to make sure, content gets set to text and also that the editText element
+ * gets updated with the modified text
+ * @param text text
+ */
+ public abstract void setText(String text);
+
+ public static EditTextAdapter createEditTextAdapter(EditText editText, String type)
+ {
+ switch (type)
+ {
+ case "4": return new EditTextAdapterGap(editText, 4);
+ case "5": return new EditTextAdapterGap(editText, 5);
+ case "6": return new EditTextAdapterGap(editText, 6);
+ case "no": return new EditTextAdapterNoGap(editText);
+ default: return new EditTextAdapterNoGap(editText);
+ }
+ }
+
+ public static class EditTextAdapterNoGap extends EditTextAdapter
+ {
+ public EditTextAdapterNoGap(EditText editText)
+ {
+ super(editText);
+ }
+
+ @Override
+ public void setText(String text)
+ {
+ this.content = text;
+ this.editText.setText(text);
+ }
+ }
+
+ public static class EditTextAdapterGap extends EditTextAdapter
+ {
+ int blockSize;
+ public EditTextAdapterGap(EditText editText, int blockSize)
+ {
+ super(editText);
+ this.blockSize = blockSize;
+ }
+
+ @Override
+ public void setText(String text)
+ {
+ this.content = text;
+ String out = "";
+ int i;
+ for(i=0; i.
+ */
+package de.vanitasvitae.enigmandroid.enigma.inputPreparer;
+
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.R;
+import de.vanitasvitae.enigmandroid.SettingsActivity;
+
+/**
+ * Preparer class that prepares input text to only consist of [A..Z]
+ * Copyright (C) 2015 Paul Schaub
+ */
+public abstract class InputPreparer {
+ InputPreparer child;
+
+ public String prepareString(String in) {
+ if (child != null)
+ return child.prepareString(this.prepare(in));
+ else
+ return prepare(in);
+ }
+
+ protected abstract String prepare(String input);
+
+ public static InputPreparer createInputPreparer()
+ {
+ MainActivity main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity();
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(main);
+
+ boolean replaceSpecialChars = sharedPreferences.getBoolean(SettingsActivity.PREF_REPLACE_SPECIAL_CHARACTERS, true);
+ String num_lang = sharedPreferences.getString(SettingsActivity.PREF_NUMERIC_LANGUAGE, main.getResources().
+ getStringArray(R.array.pref_alias_numeric_spelling_language)[0]);
+ InputPreparer inPrep = new RemoveIllegalCharacters();
+ if(replaceSpecialChars) inPrep = new ReplaceSpecialCharacters(inPrep);
+ switch (num_lang)
+ {
+ case "de": inPrep = new ReplaceNumbersGerman(inPrep);
+ break;
+ case "en": inPrep = new ReplaceNumbersEnglish(inPrep);
+ break;
+ case "fr": inPrep = new ReplaceNumbersFrench(inPrep);
+ break;
+ case "sp": inPrep = new ReplaceNumbersSpanish(inPrep);
+ break;
+ case "it": inPrep = new ReplaceNumbersItalian(inPrep);
+ break;
+ default:
+ break;
+ }
+ return inPrep;
+ }
+
+ public static class ReplaceSpecialCharacters extends InputPreparer {
+// --Commented out by Inspection START (07.11.15 19:47):
+// public ReplaceSpecialCharacters() {
+// this.child = null;
+// }
+// --Commented out by Inspection STOP (07.11.15 19:47)
+
+ public ReplaceSpecialCharacters(InputPreparer child) {
+ this.child = child;
+ }
+
+ protected String prepare(String input) {
+ input = input.toUpperCase();
+ return input.replace("Ä", "AE").replace("Ö", "OE").replace("Ü", "UE").replace("ß", "SS").replace(" ","");
+ }
+ }
+
+ /**
+ * Concrete implementation of a german InputPreparer
+ */
+ public static class ReplaceNumbersGerman extends InputPreparer {
+// --Commented out by Inspection START (07.11.15 19:47):
+// public ReplaceNumbersGerman() {
+// this.child = null;
+// }
+// --Commented out by Inspection STOP (07.11.15 19:47)
+
+ public ReplaceNumbersGerman(InputPreparer child) {
+ this.child = child;
+ }
+
+ protected String prepare(String input) {
+ input = input.replace("0", "NULL")
+ .replace("1", "EINS")
+ .replace("2", "ZWEI")
+ .replace("3", "DREI")
+ .replace("4", "VIER")
+ .replace("5", "FUENF")
+ .replace("6", "SECHS")
+ .replace("7", "SIEBEN")
+ .replace("8", "ACHT")
+ .replace("9", "NEUN");
+ return input;
+ }
+ }
+
+ /**
+ * Concrete implementation of a french InputPreparer
+ */
+ public static class ReplaceNumbersFrench extends InputPreparer {
+// --Commented out by Inspection START (07.11.15 19:47):
+// public ReplaceNumbersFrench() {
+// this.child = null;
+// }
+// --Commented out by Inspection STOP (07.11.15 19:47)
+
+ public ReplaceNumbersFrench(InputPreparer child) {
+ this.child = child;
+ }
+
+ protected String prepare(String input) {
+ input = input.replace("0", "ZERO")
+ .replace("1", "UN")
+ .replace("2", "DEUX")
+ .replace("3", "TROIS")
+ .replace("4", "QUATRE")
+ .replace("5", "CINQ")
+ .replace("6", "SIX")
+ .replace("7", "SEPT")
+ .replace("8", "HUIT")
+ .replace("9", "NEUF");
+ return input;
+ }
+ }
+
+ /**
+ * Concrete implementation of an english InputPreparer
+ */
+ public static class ReplaceNumbersEnglish extends InputPreparer {
+// --Commented out by Inspection START (07.11.15 19:47):
+// public ReplaceNumbersEnglish() {
+// this.child = null;
+// }
+// --Commented out by Inspection STOP (07.11.15 19:47)
+
+ public ReplaceNumbersEnglish(InputPreparer child) {
+ this.child = child;
+ }
+
+ protected String prepare(String input) {
+ input = input.replace("0", "ZERO")
+ .replace("1", "ONE")
+ .replace("2", "TWO")
+ .replace("3", "THREE")
+ .replace("4", "FOUR")
+ .replace("5", "FIVE")
+ .replace("6", "SIX")
+ .replace("7", "SEVEN")
+ .replace("8", "EIGHT")
+ .replace("9", "NINE");
+ return input;
+ }
+ }
+
+ /**
+ * Concrete implementation of a spanish InputPreparer
+ */
+ public static class ReplaceNumbersSpanish extends InputPreparer {
+// --Commented out by Inspection START (07.11.15 19:47):
+// public ReplaceNumbersSpanish() {
+// this.child = null;
+// }
+// --Commented out by Inspection STOP (07.11.15 19:47)
+
+ public ReplaceNumbersSpanish(InputPreparer child) {
+ this.child = child;
+ }
+
+ protected String prepare(String input) {
+ input = input.replace("0", "CERO")
+ .replace("1", "UNO")
+ .replace("2", "DOS")
+ .replace("3", "TRES")
+ .replace("4", "CUATRO")
+ .replace("5", "CINCO")
+ .replace("6", "SEIS")
+ .replace("7", "SIETE")
+ .replace("8", "OCHO")
+ .replace("9", "NUEVE");
+ return input;
+ }
+ }
+
+ /**
+ * Concrete implementation of a spanish InputPreparer
+ */
+ public static class ReplaceNumbersItalian extends InputPreparer {
+// --Commented out by Inspection START (07.11.15 19:47):
+// public ReplaceNumbersItalian() {
+// this.child = null;
+// }
+// --Commented out by Inspection STOP (07.11.15 19:47)
+
+ public ReplaceNumbersItalian(InputPreparer child) {
+ this.child = child;
+ }
+
+ protected String prepare(String input) {
+ input = input.replace("0", "ZERO")
+ .replace("1", "UNO")
+ .replace("2", "DUE")
+ .replace("3", "TRE")
+ .replace("4", "QUATTRO")
+ .replace("5", "CINQUE")
+ .replace("6", "SEI")
+ .replace("7", "SETTE")
+ .replace("8", "OTTO")
+ .replace("9", "NOVE");
+ return input;
+ }
+ }
+
+ /**
+ * "Final Stage" of Input preparing. This should always be called last
+ * (choose this as the inner most capsule of InputPreparers)
+ * This cant have child InputPreparers.
+ * This Input preparer removes all characters from the string besides A..Z
+ */
+ public static class RemoveIllegalCharacters extends InputPreparer
+ {
+ public RemoveIllegalCharacters()
+ {
+ this.child = null;
+ }
+
+ protected String prepare(String in)
+ {
+ String out = "";
+ for(char c : in.toUpperCase().toCharArray())
+ {
+ if(c>=65 && c<=90) out = out+c;
+ }
+ return out;
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/EntryWheel.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/EntryWheel.java
new file mode 100644
index 0000000..f326e19
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/EntryWheel.java
@@ -0,0 +1,135 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.enigma.parts;
+
+/**
+ * Implementation of several EntryWheels
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class EntryWheel
+{
+ private final int type;
+ private final String name;
+ private int index;
+ private final String summary;
+ private final Integer[] connections;
+ private final Integer[] reversedConnections;
+
+ EntryWheel(int type, String name, String summary, Integer[] connections, Integer[] reversedConnections)
+ {
+ this.type = type;
+ this.name = name;
+ this.summary = summary;
+ this.connections = connections;
+ this.reversedConnections = reversedConnections;
+ }
+
+ /**
+ * Returns a new EntryWheel of the same type as the callee
+ * @return new EntryWheel
+ */
+ public EntryWheel getInstance()
+ {
+ return createEntryWheel(this.type).setIndex(this.getIndex());
+ }
+
+ /**
+ * Encrypt an input signal via the internal wiring in "forward" direction towards the reflector
+ * (using connections)
+ * @param input signal
+ * @return encrypted signal
+ */
+ public int encryptForward(int input)
+ {
+ return this.connections[normalize(input)];
+ }
+
+ private int normalize(int input)
+ {
+ return (input+this.connections.length)%this.connections.length;
+ }
+
+ public EntryWheel setIndex(int index)
+ {
+ this.index = index;
+ return this;
+ }
+
+ public int getIndex()
+ {
+ return this.index;
+ }
+
+ /**
+ * Encrypt an input signal via the internal wiring in "backwards" direction (using
+ * reversedConnections)
+ * @param input signal
+ * @return encrypted signal
+ */
+ public int encryptBackward(int input)
+ {
+ return this.reversedConnections[normalize(input)];
+ }
+
+ private EntryWheel createEntryWheel(int type)
+ {
+ switch(type)
+ {
+ case 1:
+ return new EntryWheel_QWERTZ();
+ case 2:
+ return new EntryWheel_T();
+ default: return new EntryWheel_ABCDEF();
+ }
+ }
+
+ public static class EntryWheel_ABCDEF extends EntryWheel
+ {
+ public EntryWheel_ABCDEF()
+ {
+ super(0, "ABCDEF", "abcdefghijklmnopqrstuvwxyz",
+ new Integer[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25},
+ new Integer[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25});
+ }
+ }
+
+ /**
+ * EntryWheel as used in the Enigma models D, K, G
+ * Q W E R T Z U I O A S D F G H J K P Y X C V B N M L
+ */
+ public static class EntryWheel_QWERTZ extends EntryWheel
+ {
+ public EntryWheel_QWERTZ()
+ {
+ super(1, "QWERTZ", "qwertzuioasdfghjkpyxcvbnml",
+ new Integer[]{9,22,20,11,2,12,13,14,7,15,16,25,24,23,8,17,0,3,10,4,6,21,1,19,18,5},
+ new Integer[]{16,22,4,17,19,25,20,8,14,0,18,3,5,6,7,9,10,15,24,23,2,21,1,13,12,11});
+ }
+ }
+
+ /**
+ * EntryWheel as used only in the Enigma Type T Tirpitz
+ * K Z R O U Q H Y A I G B L W V S T D X F P N M C J E
+ */
+ public static class EntryWheel_T extends EntryWheel
+ {
+ public EntryWheel_T()
+ {
+ super(2, "KZROUQ", "kzrouqhyaigblwvstdxfpnmcje",
+ new Integer[]{8,11,23,17,25,19,10,6,9,24,0,12,22,21,3,20,5,2,15,16,4,14,13,18,7,1},
+ new Integer[]{10,25,17,14,20,16,7,24,0,8,6,1,11,22,21,18,19,3,23,5,15,13,12,2,9,4});
+ }
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/Plugboard.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/Plugboard.java
new file mode 100644
index 0000000..2204b47
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/Plugboard.java
@@ -0,0 +1,219 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.enigma.parts;
+
+import android.util.Log;
+
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Random;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.enigma.Enigma;
+import de.vanitasvitae.enigmandroid.enigma.inputPreparer.InputPreparer;
+
+/**
+ * Plugboard of the enigma
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class Plugboard
+{
+ private static final int[] empty = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25};
+ private int[] plugs;
+
+ public Plugboard()
+ {
+ plugs = Arrays.copyOf(empty, empty.length);
+ }
+
+ public Plugboard(int[] conf)
+ {
+ this.plugs = conf;
+ }
+
+ public void setConfiguration(int[] conf)
+ {
+ this.plugs = conf;
+ }
+
+ @SuppressWarnings("UnusedReturnValue")
+ public BigInteger setConfiguration(BigInteger b)
+ {
+ String s = "";
+
+ int x;
+ while((x = Enigma.getValue(b, 27)) != 26 && b.compareTo(BigInteger.ZERO) > 1)
+ {
+ s = ((char) (x+65))+s;
+ b = Enigma.removeDigit(b, 27);
+ }
+ this.setConfiguration(stringToConfiguration(s));
+ return b;
+ }
+
+ public int[] getConfiguration()
+ {
+ return this.plugs;
+ }
+
+ /**
+ * Encrypt input via plugboard connections
+ * @param input input symbol to encryptString
+ * @return encrypted symbol
+ */
+ public int encrypt(int input)
+ {
+ return plugs[(input+plugs.length)%plugs.length];
+ }
+
+ /**
+ * Interpret a String of Pairs as a configuration for the plugboard
+ * Any char with an even index is connected to the successor.
+ * in must not contain duplicates!
+ * @param in String representation of pairs (eg. AXBHCS...)
+ * @return connections as int[]
+ */
+ public static int[] stringToConfiguration(String in)
+ {
+ String pairs = trimString(new InputPreparer.RemoveIllegalCharacters().prepareString(in));
+ int[] out = Arrays.copyOf(empty, empty.length);
+ //Check if in is too long or odd
+ int l = pairs.length();
+ if(l>1 && (pairs.length() > 26 || pairs.length()/2 == (pairs.length()-1)/2))
+ {
+ //Odd length. remove last char. Information loss!
+ pairs = pairs.substring(0,pairs.length()-1);
+ }
+ //Modify out
+ for(int i=0; i 1)
+ {
+ s = ((char) (x+65))+s;
+ b = Enigma.removeDigit(b, 27);
+ }
+ Log.d(MainActivity.APP_ID, "Restored: "+s);
+ return stringToConfiguration(s);
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/Reflector.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/Reflector.java
new file mode 100644
index 0000000..d74d823
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/Reflector.java
@@ -0,0 +1,355 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.enigma.parts;
+
+import android.util.Log;
+
+import java.math.BigInteger;
+import java.util.Arrays;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.enigma.Enigma;
+
+/**
+ * Reflector of the enigma machine.
+ * The reflector was used to reflect the scrambled signal at the end of the wiring back to
+ * go through another (reversed but not inverting) process of scrambling.
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class Reflector
+{
+ private final int type;
+ private final String name;
+ private int index;
+ private final String summary;
+ private int[] connections;
+ private int rotation;
+ private int ringSetting;
+
+ /**
+ * This constructor is not accessible from outside this class file.
+ * Use the one of the createReflector* methods instead to create concrete Reflectors from
+ * outside this class file
+ * @param type name indicator of the reflector
+ * @param connections wiring of the reflector as Integer array
+ */
+ Reflector(int type, String name, String summary, int[] connections)
+ {
+ this.type = type;
+ this.name = name;
+ this.summary = summary;
+ this.connections = connections;
+ }
+
+ public Reflector getInstance()
+ {
+ //noinspection ConstantConditions
+ return createReflector(this.type).setIndex(this.getIndex());
+ }
+
+ public Reflector getInstance(int rotation, int ringSetting)
+ {
+ //noinspection ConstantConditions
+ return createReflector(this.type).setIndex(this.getIndex())
+ .setRotation(rotation).setRingSetting(ringSetting);
+ }
+
+ public Reflector setIndex(int index)
+ {
+ this.index = index;
+ return this;
+ }
+
+ public int getIndex()
+ {
+ return this.index;
+ }
+
+ public int getRotation()
+ {
+ return rotation;
+ }
+
+ public int getRingSetting()
+ {
+ return ringSetting;
+ }
+
+ public Reflector setRotation(int rotation)
+ {
+ this.rotation = rotation;
+ return this;
+ }
+
+ public Reflector setRingSetting(int ringSetting)
+ {
+ this.ringSetting = ringSetting;
+ return this;
+ }
+
+ public Reflector setConfiguration(int[] c)
+ {
+ this.connections = c;
+ return this;
+ }
+
+ @SuppressWarnings("UnusedReturnValue")
+ public BigInteger setConfiguration(BigInteger b)
+ {
+ String s = "";
+
+ int x;
+ while((x = Enigma.getValue(b, 27)) != 26 || b.compareTo(BigInteger.ZERO) > 1)
+ {
+ s = ((char) (x+65))+s;
+ b = Enigma.removeDigit(b, 27);
+ }
+ Log.d(MainActivity.APP_ID, "Restored: " + s);
+ this.setConfiguration(Plugboard.stringToConfiguration(s));
+ return b;
+ }
+
+ public int[] getConfiguration()
+ {
+ return connections;
+ }
+
+ /**
+ * Factory method to create reflectors.
+ * @param type name of the created reflector
+ * 1 -> ReflectorA
+ * 2 -> ReflectorB
+ * 3 -> ReflectorC
+ * 4 -> ReflectorThinB
+ * 5 -> ReflectorThinC
+ * 6 -> ReflectorEnigma_D_KD_G31
+ * 7 -> Reflector_K
+ * 8 -> Reflector_T
+ * 9 -> Reflector_G312
+ * 10 -> Reflector_G260
+ * 11 -> Reflector_R
+ * default -> ReflectorB
+ * @return Reflector
+ */
+ private static Reflector createReflector(int type)
+ {
+ switch (type)
+ {
+ case 0: return new Reflector_A();
+ case 1: return new Reflector_B();
+ case 2: return new Reflector_C();
+ case 10: return new Reflector_Thin_B();
+ case 11: return new ReflectorThinC();
+ case 20: return new ReflectorEnigma_D_G31();
+ case 21: return new ReflectorEnigma_KD();
+ case 30: return new Reflector_G312();
+ case 40: return new Reflector_K_G260();
+ case 50: return new Reflector_R();
+ case 60: return new ReflectorEnigma_T();
+
+ default:
+ Log.e(MainActivity.APP_ID," Tried to create Reflector of invalid name "+type);
+ return null;
+ }
+ }
+
+ /**
+ * Substitute an input signal via the wiring of the reflector with a different (!) output.
+ * The output MUST not be equal to the input for any input, since this was not possible
+ * due to the electronic implementation of the historical enigma machine.
+ * @param input input signal
+ * @return encrypted (substituted) output
+ */
+ public int encrypt(int input)
+ {
+ return this.connections[normalize(input)];
+ }
+
+ /**
+ * Return the size (ie the number of wires/length of the connections array) of the reflector
+ * @return size
+ */
+ private int getRotorSize()
+ {
+ return this.connections.length;
+ }
+
+ /**
+ * Normalize the input.
+ * Normalizing means keeping the input via modulo in the range from 0 to n-1, where n is equal
+ * to the size of the reflector. This is necessary since java allows negative modulo values,
+ * which can break this implementation
+ * @param input input signal
+ * @return "normalized" input signal
+ */
+ private int normalize(int input)
+ {
+ return (input + this.getRotorSize()) % this.getRotorSize();
+ }
+
+ /**
+ * Concrete implementation of ReflectorA
+ * Used in Enigma I
+ * AE BJ CM DZ FL GY HX IV KW NR OQ PU ST
+ */
+ public static class Reflector_A extends Reflector
+ {
+ public Reflector_A()
+ {
+ super(0, "A", "EJMZALYXVBWFCRQUONTSPIKHGD",
+ new int[]{4,9,12,25,0,11,24,23,21,1,22,5,2,17,16,20,14,13,19,18,15,8,10,7,6,3});
+ }
+ }
+
+ /**
+ * Concrete implementation of ReflectorB
+ * Used in Enigma I, M3
+ * AY BR CU DH EQ FS GL IP JX KN MO TZ VW
+ */
+ public static class Reflector_B extends Reflector
+ {
+ public Reflector_B()
+ {
+ super(1, "B", "YRUHQSLDPXNGOKMIEBFZCWVJAT",
+ new int[]{24,17,20,7,16,18,11,3,15,23,13,6,14,10,12,8,4,1,5,25,2,22,21,9,0,19});
+ }
+ }
+
+ /**
+ * Concrete implementation of ReflectorC
+ * Used in Enigma I, M3
+ * AF BV CP DJ EI GO HY KR LZ MX NW QT SU
+ */
+ public static class Reflector_C extends Reflector
+ {
+ public Reflector_C()
+ {
+ super(2, "C", "FVPJIAOYEDRZXWGCTKUGSBNMHL",
+ new int[]{5,21,15,9,8,0,14,24,4,3,17,25,23,22,6,2,19,10,20,16,18,1,13,12,7,11});
+ }
+ }
+
+ /**
+ * Concrete implementation of thin reflector name b (not equal to normal name b!)
+ * When used with Rotor Beta on rotation 0, the pair was equivalent to normal reflector B
+ * S->Beta->ThinB->Beta'->X == X->UKWB->S
+ * Used in Enigma M4
+ * E N K Q A U Y W J I C O P B L M D X Z V F T H R G S
+ */
+ public static class Reflector_Thin_B extends Reflector
+ {
+ public Reflector_Thin_B()
+ {
+ super(10, "Thin-B", "ENKQAUYWJICOPBLMDXZVFTHRGS",
+ new int[]{4,13,10,16,0,20,24,22,9,8,2,14,15,1,11,12,3,23,25,21,5,19,7,17,6,18});
+ }
+ }
+
+ /**
+ * Concrete implementation of thin reflector name c (not equal to normal name c!)
+ * When used with Rotor Gamma on rotation 0, the pair was equivalent to normal reflector C
+ * S->Gamma->ThinC->Gamma'->X == X->UKWC->S
+ * Used in Enigma M4
+ * R D O B J N T K V E H M L F C W Z A X G Y I P S U Q
+ */
+ public static class ReflectorThinC extends Reflector
+ {
+ public ReflectorThinC()
+ {
+ super(11, "ThinC", "RDOBJNTKVEHMLFCWZAXGYIPSUQ",
+ new int[]{17,3,14,1,9,13,19,10,21,4,7,12,11,5,2,22,25,0,23,6,24,8,15,18,20,16});
+ }
+ }
+
+ /**
+ * Pluggable Reflector of the Enigma machine of name D and G31
+ * Standard wiring: AI,BM,CE,DT,FG,HR,JY,KS,LQ,NZ,OX,PW,UV
+ * Has additional ringSetting and can rotate
+ */
+ public static class ReflectorEnigma_D_G31 extends Reflector
+ {
+ public static final int[] defaultWiring_D_G31 = {8,12,4,19,2,6,5,17,0,24,18,16,1,25,23,22,11,7,10,3,21,20,15,14,9,13};
+ public ReflectorEnigma_D_G31()
+ {
+ super(20, "Ref-D", "Default: IMETCGFRAYSQBZXWLHKDVUPOJN", Arrays.copyOf(defaultWiring_D_G31,defaultWiring_D_G31.length));
+ }
+ }
+
+ /**
+ * Pluggable Reflector as used in the Enigma of Type KD
+ * Standard wiring: KOTVPNLMJIAGHFBEWYXCZDQSRU
+ * Has additional ringSetting and can rotate
+ */
+ public static class ReflectorEnigma_KD extends Reflector
+ {
+ public static final int[] defaultWiring_KD = {10,14,19,21,15,13,11,12,9,8,0,6,7,5,1,4,22,24,23,2,25,3,16,18,17,20};
+ public ReflectorEnigma_KD()
+ {
+ super(21, "Ref-KD", "Default: KOTVPNLMJIAGHFBEWYXCZDQSRU", Arrays.copyOf(defaultWiring_KD, defaultWiring_KD.length));
+ }
+ }
+
+ /**
+ * Reflector as used in the Enigma name G-312 Abwehr
+ * R U L Q M Z J S Y G O C E T K W D A H N B X P V I F
+ */
+ public static class Reflector_G312 extends Reflector
+ {
+ public Reflector_G312()
+ {
+ super(30, "Ref-G312", "RULQMZJSYGOCETKWDAHNBXPVIF",
+ new int[]{17,20,11,16,12,25,9,18,24,6,14,2,4,19,10,22,3,0,7,13,1,23,15,21,8,5});
+ }
+ }
+
+ /**
+ * Reflector as used in the Enigma name G-260 Abwehr
+ * I M E T C G F R A Y S Q B Z X W L H K D V U P O J N
+ */
+ public static class Reflector_K_G260 extends Reflector
+ {
+ public Reflector_K_G260()
+ {
+ super(40,"Ref-K/G260", "IMETCGFRAYSQBZXWLHKDVUPOJN",
+ new int[]{8,12,4,19,2,6,5,17,0,24,18,16,1,25,23,22,11,7,10,3,21,20,15,14,9,13});
+ }
+ }
+
+ /**
+ * Reflector as used in the Enigma Type R "Rocket" (Reichsbahn)
+ * Q Y H O G N E C V P U Z T F D J A X W M K J S R B L
+ */
+ public static class Reflector_R extends Reflector
+ {
+ public Reflector_R()
+ {
+ super(50, "Ref-R", "QYHOGNECVPUZTFDJAXWMKJSRBL",
+ new int[]{16,24,7,14,6,13,4,2,21,15,20,25,19,5,3,9,0,23,22,12,10,8,18,17,1,11});
+ }
+ }
+
+ /**
+ * Reflector as used in the Enigma name T (Tirpitz)
+ * G E K P B T A U M O C N I L J D X Z Y F H W V Q S R
+ */
+ public static class ReflectorEnigma_T extends Reflector
+ {
+ public ReflectorEnigma_T()
+ {
+ super(60, "Ref-T", "GEKPBTAUMOCNILJDXZYFHWVQSR",
+ new int[]{6,4,10,15,1,19,0,20,12,14,2,13,8,11,9,3,23,25,24,5,7,22,21,16,18,17});
+ }
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/Rotor.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/Rotor.java
new file mode 100644
index 0000000..a797fcf
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/Rotor.java
@@ -0,0 +1,1029 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.enigma.parts;
+
+import android.util.Log;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+
+/**
+ * Rotor super class and inner concrete implementations
+ * The rotors were the key feature of the enigma used to scramble up input signals into
+ * encrypted signals difficult to predict. The rotors rotated to achieve a poly-alphabetic
+ * substitution which was hard to break. Each signal passes the rotor twice. Once in "forward"-
+ * direction and once in "backwards"-direction. There was a set of 3 out of 5 rotors inside the
+ * enigma machine M4.
+ * Copyright (C) 2015 Paul Schaub
+ */
+public abstract class Rotor
+{
+ /** Number of the rotor (used internally to create the Rotor via createRotor() ) */
+ private final int type;
+
+ /** Identifier of the Rotor */
+ private final String name;
+
+ /** Index of the Rotor in the parent machine's selection Spinner */
+ private int index;
+
+ /** Summary of the connections (internal wiring) */
+ private final String summary;
+
+ /** Wiring of the rotor when the signal passes the first time */
+ private final Integer[] connections;
+
+ /** Wiring of the rotor when the signal passes the second time (inverse of the first time) */
+ private final Integer[] reversedConnections;
+
+ /** When the Rotor is at this Position and jumps one over, it also turns the next */
+ private final Integer[] turnOverNotches;
+
+ /** Offset of the labeled ring of the rotor */
+ private int ringSetting;
+
+ /** Rotation of the rotor */
+ private int rotation;
+
+ /**
+ * This constructor is not accessible from outside this class file.
+ * Use one of the createRotor* factory methods instead to create concrete Rotors.
+ * Note that connections and reversedConnections MUST be of the same size and that
+ * neither connections nor reversedConnections respectively MUST have any number between
+ * 0 and connections.length-1 only once (ie they represent permutations)
+ * @param name name indicator
+ * @param connections wiring of the rotor as Integer array
+ * @param reversedConnections inverse wiring used to encryptString in the opposite direction
+ * (connections[reversedConnections[i]] = i
+ * for all i in 0..getRotorSize()-1.
+ * @param turnOverNotches Position(s) of the turnover notch(es)
+ * @param ringSetting setting of the ring that holds the letters
+ * @param rotation rotation of the rotor
+ */
+ Rotor(int type, String name, String summary, Integer[] connections, Integer[] reversedConnections,
+ Integer[] turnOverNotches, int ringSetting, int rotation)
+ {
+ this.type = type;
+ this.name = name;
+ this.summary = summary;
+ this.connections = connections;
+ this.reversedConnections = reversedConnections;
+ this.turnOverNotches = turnOverNotches;
+ this.ringSetting = ringSetting;
+ this.rotation = rotation;
+ }
+
+ /**
+ * Create a new Rotor of the same type as the callee.
+ * @param rotation rotation of the new Rotor
+ * @param ringSetting ringSetting of the new Rotor
+ * @return new Rotor
+ */
+ public Rotor getInstance(int rotation, int ringSetting)
+ {
+ //noinspection ConstantConditions
+ return createRotor(this.type, rotation, ringSetting).setIndex(this.getIndex());
+ }
+
+ /**
+ * Create a new Rotor of the same type as the callee.
+ * @return new Rotor
+ */
+ public Rotor getInstance()
+ {
+ //noinspection ConstantConditions
+ return createRotor(this.type, 0, 0).setIndex(this.getIndex());
+ }
+
+ private static Rotor createRotor(int type, int rotation, int ringSetting)
+ {
+ Log.d(MainActivity.APP_ID, "Rotor creation: "+type);
+ switch (type)
+ {
+ case 0: return new Rotor_I(rotation, ringSetting);
+ case 1: return new Rotor_II(rotation, ringSetting);
+ case 2: return new Rotor_III(rotation, ringSetting);
+ case 3: return new Rotor_IV(rotation, ringSetting);
+ case 4: return new Rotor_V(rotation, ringSetting);
+ case 5: return new Rotor_VI(rotation, ringSetting);
+ case 6: return new Rotor_VII(rotation, ringSetting);
+ case 7: return new Rotor_VIII(rotation, ringSetting);
+
+ case 10: return new Rotor_M4_Beta(rotation, ringSetting);
+ case 11: return new Rotor_M4_Gamma(rotation, ringSetting);
+
+ case 20: return new Rotor_G31_I(rotation, ringSetting);
+ case 21: return new Rotor_G31_II(rotation, ringSetting);
+ case 22: return new Rotor_G31_III(rotation, ringSetting);
+
+ case 30: return new Rotor_G312_I(rotation, ringSetting);
+ case 31: return new Rotor_G312_II(rotation, ringSetting);
+ case 32: return new Rotor_G312_III(rotation, ringSetting);
+
+ case 40: return new Rotor_G260_I(rotation, ringSetting);
+ case 41: return new Rotor_G260_II(rotation, ringSetting);
+ case 42: return new Rotor_G260_III(rotation, ringSetting);
+
+ case 50: return new Rotor_K_D_I(rotation, ringSetting);
+ case 51: return new Rotor_K_D_II(rotation, ringSetting);
+ case 52: return new Rotor_K_D_III(rotation, ringSetting);
+
+ case 60: return new Rotor_KD_I(rotation, ringSetting);
+ case 61: return new Rotor_KD_II(rotation, ringSetting);
+ case 62: return new Rotor_KD_III(rotation, ringSetting);
+
+ case 70: return new Rotor_KSwiss_Standard_I(rotation, ringSetting);
+ case 71: return new Rotor_KSwiss_Standard_II(rotation, ringSetting);
+ case 72: return new Rotor_KSwiss_Standard_III(rotation, ringSetting);
+
+ case 80: return new Rotor_K_Swiss_Airforce_I(rotation, ringSetting);
+ case 81: return new Rotor_K_Swiss_Airforce_II(rotation, ringSetting);
+ case 82: return new Rotor_K_Swiss_Airforce_III(rotation, ringSetting);
+
+ case 90: return new Rotor_R_I(rotation, ringSetting);
+ case 91: return new Rotor_R_II(rotation, ringSetting);
+ case 92: return new Rotor_R_III(rotation, ringSetting);
+
+ case 100: return new Rotor_T_I(rotation, ringSetting);
+ case 101: return new Rotor_T_II(rotation, ringSetting);
+ case 102: return new Rotor_T_III(rotation, ringSetting);
+ case 103: return new Rotor_T_IV(rotation, ringSetting);
+ case 104: return new Rotor_T_V(rotation, ringSetting);
+ case 105: return new Rotor_T_VI(rotation, ringSetting);
+ case 106: return new Rotor_T_VII(rotation, ringSetting);
+ case 107: return new Rotor_T_VIII(rotation, ringSetting);
+
+ default: Log.e(MainActivity.APP_ID," Tried to create Rotor of invalid name "+type);
+ return null;
+ }
+ }
+
+ /**
+ * Encrypt an input signal via the internal wiring in "forward" direction towards the reflector
+ * (using connections)
+ * @param input signal
+ * @return encrypted signal
+ */
+ public int encryptForward(int input)
+ {
+ return this.connections[normalize(input)];
+ }
+
+ /**
+ * Encrypt an input signal via the internal wiring in "backwards" direction (using
+ * reversedConnections)
+ * @param input signal
+ * @return encrypted signal
+ */
+ public int encryptBackward(int input)
+ {
+ return this.reversedConnections[normalize(input)];
+ }
+
+ /**
+ * Return the name indicator (usually 1..5)
+ * @return name indicator
+ */
+ public String getName()
+ {
+ return this.name;
+ }
+
+ /**
+ * Return the index of this Rotor
+ * @return index
+ */
+ public int getIndex()
+ {
+ return this.index;
+ }
+
+ /**
+ * Set the index of this Rotor. The index refers to the selector Spinner of the machine, this
+ * Rotor is used in.
+ * @param index index in the Spinner
+ * @return this
+ */
+ public Rotor setIndex(int index)
+ {
+ this.index = index;
+ return this;
+ }
+
+ public Rotor setRotation(int r)
+ {
+ this.rotation = r%this.getRotorSize();
+ return this;
+ }
+
+ public Rotor setRingSetting(int r)
+ {
+ this.ringSetting = r%this.getRotorSize();
+ return this;
+ }
+
+ /**
+ * Return the current rotation of the rotor.
+ * The rotation consists of the actual rotation - the ringSetting
+ * @return rotation-ringSetting
+ */
+ public int getRotation()
+ {
+ return this.rotation;
+ }
+
+ /**
+ * Increment rotation of the rotor by one.
+ */
+ public Rotor rotate()
+ {
+ this.rotation = normalize(this.getRotation()+1);
+ return this;
+ }
+
+ /**
+ * Return true, if the rotor is at a position, where it turns over the next rotor by one
+ * @return rotation==turnOverNotch
+ */
+ public boolean isAtTurnoverPosition()
+ {
+ for(int x : getTurnOverNotches())
+ {
+ //if(x == this.rotation + this.ringSetting) return true;
+ if(x == this.rotation) return true;
+ }
+ return false;
+ }
+
+ /**
+ * Return true, if the rotor is in a position where the double turn anomaly happens.
+ * The double turn anomaly (german: Doppelsprung-Anomalie) is an anomaly in the rotor movement
+ * caused by the mechanical implementation of the enigma.
+ * Whenever the rightmost rotor turns the middle rotor AND the middle rotor is only one move
+ * from turning the leftmost rotor, the middle rotor turns again with the next character.
+ * So technically there are only 26*25*26 possible rotor settings for any but firmly 3 rotors.
+ * @return rotation == turnOverNotch-1
+ */
+ public boolean doubleTurnAnomaly()
+ {
+ for(int x : getTurnOverNotches())
+ {
+ if(this.rotation == x-1) return true;
+ }
+ return false;
+ }
+
+ /**
+ * Returns the positions of the turnover notches in a array
+ * @return turnOverNotches
+ */
+ private Integer[] getTurnOverNotches()
+ {
+ return this.turnOverNotches;
+ }
+
+ /**
+ * Return ringSettings of the rotor
+ * @return ringSetting
+ */
+ public int getRingSetting()
+ {
+ return this.ringSetting;
+ }
+
+
+ /**
+ * Returns the size (ie the number of wires/size of the connections array)
+ * of the rotor
+ * @return size
+ */
+ private int getRotorSize()
+ {
+ return this.connections.length;
+ }
+
+ /**
+ * Normalize the input.
+ * Normalizing means keeping the input via modulo in the range from 0 to n-1, where n is equal
+ * to the size of the rotor. This is necessary since java allows negative modulo values,
+ * which can break this implementation
+ * @param input input signal
+ * @return "normalized" input signal
+ */
+ public int normalize(int input)
+ {
+ return (input+this.getRotorSize())%this.getRotorSize();
+ }
+
+ /**
+ * Concrete implementation of Rotor of name 1 (I)
+ * Used in Enigma I, M3, M4
+ * E K M F L G D Q V Z N T O W Y H X U S P A I B R C J
+ */
+ public static class Rotor_I extends Rotor
+ {
+ public Rotor_I(int rotation, int ringSetting)
+ {
+ super(0, "I", "EKMFLGDQVZNTOWYHXUSPAIBRCJ",
+ new Integer[]{4, 10, 12, 5, 11, 6, 3, 16, 21, 25, 13, 19, 14, 22, 24, 7, 23, 20, 18, 15, 0, 8, 1, 17, 2, 9},
+ new Integer[]{20, 22, 24, 6, 0, 3, 5, 15, 21, 25, 1, 4, 2, 10, 12, 19, 7, 23, 18, 11, 17, 8, 13, 16, 14, 9},
+ new Integer[]{17}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Concrete implementation of Rotor of name 2 (II)
+ * Used in Enigma I, M3, M4
+ * A J D K S I R U X B L H W T M C Q G Z N P Y F V O E
+ */
+ public static class Rotor_II extends Rotor
+ {
+ public Rotor_II(int rotation, int ringSetting)
+ {
+ super(1, "II", "AJDKSIRUXBLHWTMCQGZNPYFVOE",
+ new Integer[]{0, 9, 3, 10, 18, 8, 17, 20, 23, 1, 11, 7, 22, 19, 12, 2, 16, 6, 25, 13, 15, 24, 5, 21, 14, 4},
+ new Integer[]{0, 9, 15, 2, 25, 22, 17, 11, 5, 1, 3, 10, 14, 19, 24, 20, 16, 6, 4, 13, 7, 23, 12, 8, 21, 18},
+ new Integer[]{5}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Concrete implementation of Rotor of name 3 (III)
+ * Used in Enigma I, M3, M4
+ * B D F H J L C P R T X V Z N Y E I W G A K M U S Q O
+ */
+ public static class Rotor_III extends Rotor
+ {
+ public Rotor_III(int rotation, int ringSetting)
+ {
+ super(2, "III", "BDFHJLCPRTXVZNYEIWGAKMUSQO",
+ new Integer[]{1, 3, 5, 7, 9, 11, 2, 15, 17, 19, 23, 21, 25, 13, 24, 4, 8, 22, 6, 0, 10, 12, 20, 18, 16, 14},
+ new Integer[]{19, 0, 6, 1, 15, 2, 18, 3, 16, 4, 20, 5, 21, 13, 25, 7, 24, 8, 23, 9, 22, 11, 17, 10, 14, 12},
+ new Integer[]{22}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Concrete implementation of Rotor of name 4 (IV)
+ * Used in Enigma M3, M4
+ * E S O V P Z J A Y Q U I R H X L N F T G K D C M W B
+ */
+ public static class Rotor_IV extends Rotor
+ {
+ public Rotor_IV(int rotation, int ringSetting)
+ {
+ super(3, "IV", "ESOVPZJAYQUIRHXLNFTGKDCMWB",
+ new Integer[]{4, 18, 14, 21, 15, 25, 9, 0, 24, 16, 20, 8, 17, 7, 23, 11, 13, 5, 19, 6, 10, 3, 2, 12, 22, 1},
+ new Integer[]{7, 25, 22, 21, 0, 17, 19, 13, 11, 6, 20, 15, 23, 16, 2, 4, 9, 12, 1, 18, 10, 3, 24, 14, 8, 5},
+ new Integer[]{10}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Concrete implementation of Rotor of name 5 (V)
+ * Used in Enigma M3, M4
+ * V Z B R G I T Y U P S D N H L X A W M J Q O F E C K
+ */
+ public static class Rotor_V extends Rotor
+ {
+ public Rotor_V(int rotation, int ringSetting)
+ {
+ super(4, "V", "VZBRGITYUPSDNHLXAWMJQOFECK",
+ new Integer[]{21, 25, 1, 17, 6, 8, 19, 24, 20, 15, 18, 3, 13, 7, 11, 23, 0, 22, 12, 9, 16, 14, 5, 4, 2, 10},
+ new Integer[]{16, 2, 24, 11, 23, 22, 4, 13, 5, 19, 25, 14, 18, 12, 21, 9, 20, 3, 10, 6, 8, 0, 17, 15, 7, 1},
+ new Integer[]{0}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Concrete implementation of Rotor of name 6 (VI)
+ * Used in Enigma M3, M4
+ * J P G V O U M F Y Q B E N H Z R D K A S X L I C T W
+ */
+ public static class Rotor_VI extends Rotor
+ {
+ public Rotor_VI(int rotation, int ringSetting)
+ {
+ super(5, "VI", "JPGVOUMFYQBENHZRDKASXLICTW",
+ new Integer[]{9,15,6,21,14,20,12,5,24,16,1,4,13,7,25,17,3,10,0,18,23,11,8,2,19,22},
+ new Integer[]{18,10,23,16,11,7,2,13,22,0,17,21,6,12,4,1,9,15,19,24,5,3,25,20,8,14},
+ new Integer[]{0,13}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Concrete implementation of Rotor of name 7 (VII)
+ * Used in Enigma M3, M4
+ * N Z J H G R C X M Y S W B O U F A I V L P E K Q D T
+ */
+ public static class Rotor_VII extends Rotor
+ {
+ public Rotor_VII(int rotation, int ringSetting)
+ {
+ super(6, "VII", "NZJHGRCXMYSWBOUFAIVLPEKQDT",
+ new Integer[]{13,25,9,7,6,17,2,23,12,24,18,22,1,14,20,5,0,8,21,11,15,4,10,16,3,19},
+ new Integer[]{16,12,6,24,21,15,4,3,17,2,22,19,8,0,13,20,23,5,10,25,14,18,11,7,9,1},
+ new Integer[]{0,13}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Concrete implementation of Rotor of name 8 (VIII)
+ * Used in Enigma M3, M4
+ * F K Q H T L X O C B J S P D Z R A M E W N I U Y G V
+ */
+ public static class Rotor_VIII extends Rotor
+ {
+ public Rotor_VIII(int rotation, int ringSetting)
+ {
+ super(7, "VIII", "FKQHTLXOCBJSPDZRAMEWNIUYGV",
+ new Integer[]{5,10,16,7,19,11,23,14,2,1,9,18,15,3,25,17,0,12,4,22,13,8,20,24,6,21},
+ new Integer[]{16,9,8,13,18,0,24,3,21,10,1,5,17,20,7,12,2,15,11,4,22,25,19,6,23,14},
+ new Integer[]{0,13}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Concrete implementation of Rotor of name beta (Griechenwalze Beta)
+ * Beta was used as a "thin" rotor in the M4. It was thinner than a "normal" rotor, so it
+ * could be used together with one of the two thin reflectors as one rotor.
+ * When used together with ReflectorThinB, Beta was equivalent to Reflector B (if rotation == 0)
+ * That way the M4 was backwards compatible to the M3
+ * Used in M4
+ */
+ public static class Rotor_M4_Beta extends Rotor
+ {
+ public Rotor_M4_Beta(int rotation, int ringSetting)
+ {
+ super(10, "Beta", "LEYJVCNIXWPBQMDRTAKZGFUHOS",
+ new Integer[]{11,4,24,9,21,2,13,8,23,22,15,1,16,12,3,17,19,0,10,25,6,5,20,7,14,18},
+ new Integer[]{17,11,5,14,1,21,20,23,7,3,18,0,13,6,24,10,12,15,25,16,22,4,9,8,2,19},
+ new Integer[]{}, ringSetting, rotation);
+ }
+ @Override
+ public Rotor rotate()
+ {
+ //Thin rotors are fixed in position, so they don't rotate
+ return this;
+ }
+
+ @Override
+ public boolean doubleTurnAnomaly()
+ {
+ //Nope, no anomaly
+ return false;
+ }
+ }
+
+ /**
+ * Concrete implementation of Rotor of name gamma (Griechenwalze Gamma)
+ * Gamma was used as a "thin" rotor in the M4. It was thinner than a "normal" rotor, so it
+ * could be used together with one of the two thin reflectors as one rotor.
+ * When used together with ReflectorThinC, Gamma is equivalent to Reflector C
+ * (if rotation == 0). That way the M4 was backwards compatible to the M3
+ * Used in M4
+ */
+ public static class Rotor_M4_Gamma extends Rotor
+ {
+ public Rotor_M4_Gamma(int rotation, int ringSetting)
+ {
+ super(11, "Gamma", "FSOKANUERHMBTIYCWLQPZXVGJD",
+ new Integer[]{5,18,14,10,0,13,20,4,17,7,12,1,19,8,24,2,22,11,16,15,25,23,21,6,9,3},
+ new Integer[]{4,11,15,25,7,0,23,9,13,24,3,17,10,5,2,19,18,8,1,12,6,22,16,21,14,20},
+ new Integer[]{}, ringSetting, rotation);
+ }
+ @Override
+ public Rotor rotate()
+ {
+ //Thin rotors are fixed in position, so they don't rotate
+ return this;
+ }
+
+ @Override
+ public boolean doubleTurnAnomaly()
+ {
+ //Thin rotors don't do such weird stuff, they're normal just like you and me.
+ return false;
+ }
+ }
+
+ /**
+ * Rotor I as used in the Enigma Type G31 Abwehr
+ * L P G S Z M H A E O Q K V X R F Y B U T N I C J D W
+ * Turnover T V W X A B C D F G H J L M P Q R
+ */
+ public static class Rotor_G31_I extends Rotor
+ {
+ public Rotor_G31_I(int rotation, int ringSetting)
+ {
+ super(20, "G31-I", "LPGSZMHAEOQKVXRFYBUTNICJDW",
+ new Integer[]{11,15,6,18,25,12,7,0,4,14,16,10,21,23,17,5,24,1,20,19,13,8,2,9,3,22},
+ new Integer[]{7,17,22,24,8,15,2,6,21,23,11,0,5,20,9,1,10,14,3,19,18,12,25,13,16,4},
+ new Integer[]{19,21,22,23,0,1,2,3,5,6,7,9,11,12,15,16,17}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor II as used in the Enigma Type G31 Abwehr
+ * S L V G B T F X J Q O H E W I R Z Y A M K P C N D U
+ * Turnover T U W Z A B D E G H I L N O R
+ */
+ public static class Rotor_G31_II extends Rotor
+ {
+ public Rotor_G31_II(int rotation, int ringSetting)
+ {
+ super(21, "G31_II", "SLVGBTFXJQOHEWIRZYAMKPCNDU",
+ new Integer[]{18,11,21,6,1,19,5,23,9,16,14,7,4,22,8,17,25,24,0,12,10,15,2,13,3,20},
+ new Integer[]{18,4,22,24,12,6,3,11,14,8,20,1,19,23,10,21,9,15,0,5,25,2,13,7,17,16},
+ new Integer[]{19,20,22,25,0,1,3,4,6,7,8,11,13,14,17}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor III as used in the Enigma Type G31 Abwehr
+ * C J G D P S H K T U R A W Z X F M Y N Q O B V L I E
+ * Turnover V X Y B F G I L N O S
+ */
+ public static class Rotor_G31_III extends Rotor
+ {
+ public Rotor_G31_III(int rotation, int ringSetting)
+ {
+ super(22, "G31_III", "CJGDPSHKTURAWZXFMYNQOBVLIE",
+ new Integer[]{2,9,6,3,15,18,7,10,19,20,17,0,22,25,23,5,12,24,13,16,14,1,21,11,8,4},
+ new Integer[]{11,21,0,3,25,15,2,6,24,1,7,23,16,18,20,4,19,10,5,8,9,22,12,14,17,13},
+ new Integer[]{21,23,24,1,5,6,8,11,13,14,18}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor I as used in the Enigma Type G312 Abwehr
+ * D M T W S I L R U Y Q N K F E J C A Z B P G X O H V
+ * Turnover T V W X A B C D F G H J L M P Q R
+ */
+ public static class Rotor_G312_I extends Rotor
+ {
+ public Rotor_G312_I(int rotation, int ringSetting)
+ {
+ super(30, "G312-I", "DMTWSILRUYQNKFEJCAZBPGXOHV",
+ new Integer[]{3,12,19,22,18,8,11,17,20,24,16,13,10,5,4,9,2,0,25,1,15,6,23,14,7,21},
+ new Integer[]{17,19,16,0,14,13,21,24,5,15,12,6,1,11,23,20,10,7,4,2,8,25,3,22,9,18},
+ new Integer[]{19,21,22,23,0,1,2,3,5,6,7,9,11,12,15,16,17}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor II as used in the Enigma Type G312 Abwehr
+ * H Q Z G P J T M O B L N C I F D Y A W V E U S R K X
+ * Turnover T U W Z A B D E G H I L N O R
+ */
+ public static class Rotor_G312_II extends Rotor
+ {
+ public Rotor_G312_II(int rotation, int ringSetting)
+ {
+ super(31, "G312-II", "HQZGPJTMOBLNCIFDYAWVEUSRKX",
+ new Integer[]{7,16,25,6,15,9,19,12,14,1,11,13,2,8,5,3,24,0,22,21,4,20,18,17,10,23},
+ new Integer[]{17,9,12,15,20,14,3,0,13,5,24,10,7,11,8,4,1,23,22,6,21,19,18,25,16,2},
+ new Integer[]{19,20,22,25,0,1,3,4,6,7,8,11,13,14,17}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor III as used in the Enigma Type G312 Abwehr
+ * U Q N T L S Z F M R E H D P X K I B V Y G J C W O A
+ * Turnover V X Y B F G I L N O S
+ */
+ public static class Rotor_G312_III extends Rotor
+ {
+ public Rotor_G312_III(int rotation, int ringSetting)
+ {
+ super(32, "G312-III", "UQNTLSZFMREHDPXKIBVYGJCWOA",
+ new Integer[]{20,16,13,19,11,18,25,5,12,17,4,7,3,15,23,10,8,1,21,24,6,9,2,22,14,0},
+ new Integer[]{25,17,22,12,10,7,20,11,16,21,15,4,8,2,24,13,1,9,5,3,0,18,23,14,19,6},
+ new Integer[]{21,23,24,1,5,6,8,11,13,14,18}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor I as used in the Enigma Type G260 Abwehr
+ * R C S P B L K Q A U M H W Y T I F Z V G O J N E X D
+ * Turnover T V W X A B C D F G H J L M P Q R
+ */
+ public static class Rotor_G260_I extends Rotor
+ {
+ public Rotor_G260_I(int rotation, int ringSetting)
+ {
+ super(40, "G260-I", "RCSPBLKQAUMHWYTIFZVGOJNEXD",
+ new Integer[]{17,2,18,15,1,11,10,16,0,20,12,7,22,24,19,8,5,25,21,6,14,9,13,4,23,3},
+ new Integer[]{8,4,1,25,23,16,19,11,15,21,6,5,10,22,20,3,7,0,2,14,9,18,12,24,13,17},
+ new Integer[]{19,21,22,23,0,1,2,3,5,6,7,9,11,12,15,16,17}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor II as used in the Enigma Type G260 Abwehr
+ * W C M I B V P J X A R O S G N D L Z K E Y H U F Q T
+ * Turnover T U W Z A B D E G H I L N O R
+ */
+ public static class Rotor_G260_II extends Rotor
+ {
+ public Rotor_G260_II(int rotation, int ringSetting)
+ {
+ super(41, "G260-II", "WCMIBVPJXAROSGNDLZKEYHUFQT",
+ new Integer[]{22,2,12,8,1,21,15,9,23,0,17,14,18,6,13,3,11,25,10,4,24,7,20,5,16,19},
+ new Integer[]{9,4,1,15,19,23,13,21,3,7,18,16,2,14,11,6,24,10,12,25,22,5,0,8,20,17},
+ new Integer[]{19,20,22,25,0,1,3,4,6,7,8,11,13,14,17}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor III as used in the Enigma Type G260 Abwehr
+ * F V D H Z E L S Q M A X O K Y I W P G C B U J T N R
+ * Turnover V X Y B F G I L N O S
+ */
+ public static class Rotor_G260_III extends Rotor
+ {
+ public Rotor_G260_III(int rotation, int ringSetting)
+ {
+ super(42, "G260-III", "FVDHZELSQMAXOKYIWPGCBUJTNR",
+ new Integer[]{5,21,3,7,25,4,11,18,16,12,0,23,14,10,24,8,22,15,6,2,1,20,9,19,13,17},
+ new Integer[]{10,20,19,2,5,0,18,3,15,22,13,6,9,24,12,17,8,25,7,23,21,1,16,11,14,4},
+ new Integer[]{21,23,24,1,5,6,8,11,13,14,18}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor I as used in the Enigma Type K,D
+ * L P G S Z M H A E O Q K V X R F Y B U T N I C J D W
+ * Turnover Z
+ */
+ public static class Rotor_K_D_I extends Rotor
+ {
+ public Rotor_K_D_I(int rotation, int ringSetting)
+ {
+ super(50, "K/D-I", "LPGSZMHAEOQKVXRFYBUTNICJDW",
+ new Integer[]{11,15,6,18,25,12,7,0,4,14,16,10,21,23,17,5,24,1,20,19,13,8,2,9,3,22},
+ new Integer[]{7,17,22,24,8,15,2,6,21,23,11,0,5,20,9,1,10,14,3,19,18,12,25,13,16,4},
+ new Integer[]{25}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor II as used in the Enigma Type K,D
+ * S L V G B T F X J Q O H E W I R Z Y A M K P C N D U
+ * Turnover F
+ */
+ public static class Rotor_K_D_II extends Rotor
+ {
+ public Rotor_K_D_II(int rotation, int ringSetting)
+ {
+ super(51, "K/D-II", "SLVGBTFXJQOHEWIRZYAMKPCNDU",
+ new Integer[]{18,11,21,6,1,19,5,23,9,16,14,7,4,22,8,17,25,24,0,12,10,15,2,13,3,20},
+ new Integer[]{18,4,22,24,12,6,3,11,14,8,20,1,19,23,10,21,9,15,0,5,25,2,13,7,17,16},
+ new Integer[]{5}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor III as used in the Enigma Type K,D
+ * C J G D P S H K T U R A W Z X F M Y N Q O B V L I E
+ * Turnover O
+ */
+ public static class Rotor_K_D_III extends Rotor
+ {
+ public Rotor_K_D_III(int rotation, int ringSetting)
+ {
+ super(52, "K/D-III", "CJGDPSHKTURAWZXFMYNQOBVLIE",
+ new Integer[]{2,9,6,3,15,18,7,10,19,20,17,0,22,25,23,5,12,24,13,16,14,1,21,11,8,4},
+ new Integer[]{11,21,0,3,25,15,2,6,24,1,7,23,16,18,20,4,19,10,5,8,9,22,12,14,17,13},
+ new Integer[]{14}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor I as used in the Enigma Type KD
+ * VEZIOJCXKYDUNTWAPLQGBHSFMR
+ * Turnover TVZBFIMOR
+ */
+ public static class Rotor_KD_I extends Rotor
+ {
+ public Rotor_KD_I(int rotation, int ringSetting)
+ {
+ super(60, "KD-I", "VEZIOJCXKYDUNTWAPLQGBHSFMR",
+ new Integer[]{21,4,25,8,14,9,2,23,10,24,3,20,13,19,22,0,15,11,16,6,1,7,18,5,12,17},
+ new Integer[]{15,20,6,10,1,23,19,21,3,5,8,17,24,12,4,16,18,25,22,13,11,0,14,7,9,2},
+ new Integer[]{19,21,25,1,5,8,12,14,17}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor II as used in the Enigma Type KD
+ * HGRBSJZETDLVPMQYCXAOKINFUW
+ * Turnover TVZBFIMOR
+ */
+ public static class Rotor_KD_II extends Rotor
+ {
+ public Rotor_KD_II(int rotation, int ringSetting)
+ {
+ super(61, "KD-II", "HGRBSJZETDLVPMQYCXAOKINFUW",
+ new Integer[]{7,6,17,1,18,9,25,4,19,3,11,21,15,12,16,24,2,23,0,14,10,8,13,5,20,22},
+ new Integer[]{18,3,16,9,7,23,1,0,21,5,20,10,13,22,19,12,14,2,4,8,24,11,25,17,15,6},
+ new Integer[]{19,21,25,1,5,8,12,14,17}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor III as used in the Enigma Type KD
+ * NWLHXGRBYOJSAZDVTPKFQMEUIC
+ * Turnover TVZBFIMOR
+ */
+ public static class Rotor_KD_III extends Rotor
+ {
+ public Rotor_KD_III(int rotation, int ringSetting)
+ {
+ super(62, "KD-II", "NWLHXGRBYOJSAZDVTPKFQMEUIC",
+ new Integer[]{13,22,11,7,23,6,17,1,24,14,9,18,0,25,3,21,19,15,10,5,16,12,4,20,8,2},
+ new Integer[]{12,7,25,14,22,19,5,3,24,10,18,2,21,0,9,17,20,6,11,16,23,15,1,4,8,13},
+ new Integer[]{19,21,25,1,5,8,12,14,17}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor I as used in the Enigma Type K (Switzerland)
+ * P E Z U O H X S C V F M T B G L R I N Q J W A Y D K
+ * Turnover Z
+ */
+ public static class Rotor_KSwiss_Standard_I extends Rotor
+ {
+ public Rotor_KSwiss_Standard_I(int rotation, int ringSetting)
+ {
+ super(70, "KS-I", "PEZUOHXSCVFMTBGLRINQJWAYDK",
+ new Integer[]{15,4,25,20,14,7,23,18,2,21,5,12,19,1,6,11,17,8,13,16,9,22,0,24,3,10},
+ new Integer[]{22,13,8,24,1,10,14,5,17,20,25,15,11,18,4,0,19,16,7,12,3,9,21,6,23,2},
+ new Integer[]{25}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor II as used in the Enigma Type K (Switzerland)
+ * Z O U E S Y D K F W P C I Q X H M V B L G N J R A T
+ * Turnover F
+ */
+ public static class Rotor_KSwiss_Standard_II extends Rotor
+ {
+ public Rotor_KSwiss_Standard_II(int rotation, int ringSetting)
+ {
+ super(71, "KS-II", "ZOUESYDKFWPCIQXHMVBLGNJRAT",
+ new Integer[]{25,14,20,4,18,24,3,10,5,22,15,2,8,16,23,7,12,21,1,11,6,13,9,17,0,19},
+ new Integer[]{24,18,11,6,3,8,20,15,12,22,7,19,16,21,1,10,13,23,4,25,2,17,9,14,5,0},
+ new Integer[]{5}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor III as used in the Enigma Type K (Switzerland)
+ * E H R V X G A O B Q U S I M Z F L Y N W K T P D J C
+ * Turnover O
+ */
+ public static class Rotor_KSwiss_Standard_III extends Rotor
+ {
+ public Rotor_KSwiss_Standard_III(int rotation, int ringSetting)
+ {
+ super(72, "KS-III", "EHRVXGAOBQUSIMZFLYNWKTPDJC",
+ new Integer[]{4,7,17,21,23,6,0,14,1,16,20,18,8,12,25,5,11,24,13,22,10,19,15,3,9,2},
+ new Integer[]{6,8,25,23,0,15,5,1,12,24,20,16,13,18,7,22,9,2,11,21,10,3,19,4,17,14},
+ new Integer[]{14}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor I as used in the Enigma Type K (Swiss, Airforce)
+ * PEZUOHXSCVFMTBGLRINQJWAYDK
+ * Turnover Z
+ */
+ public static class Rotor_K_Swiss_Airforce_I extends Rotor
+ {
+ public Rotor_K_Swiss_Airforce_I(int rotation, int ringSetting)
+ {
+ super(80, "KSA-I", "PEZUOHXSCVFMTBGLRINQJWAYDK",
+ new Integer[]{15,4,25,20,14,7,23,18,2,21,5,12,19,1,6,11,17,8,13,16,9,22,0,24,3,10},
+ new Integer[]{22,13,8,24,1,10,14,5,17,20,25,15,11,18,4,0,19,16,7,12,3,9,21,6,23,2},
+ new Integer[]{25}, ringSetting, rotation);
+ }
+ }
+ /**
+ * Rotor II as used in the Enigma Type K (Swiss, Airforce)
+ * ZOUESYDKFWPCIQXHMVBLGNJRAT
+ * Turnover F
+ */
+ public static class Rotor_K_Swiss_Airforce_II extends Rotor
+ {
+ public Rotor_K_Swiss_Airforce_II(int rotation, int ringSetting)
+ {
+ super(81, "KSA-II", "ZOUESYDKFWPCIQXHMVBLGNJRAT",
+ new Integer[]{25,14,20,4,18,24,3,10,5,22,15,2,8,16,23,7,12,21,1,11,6,13,9,17,0,19},
+ new Integer[]{24,18,11,6,3,8,20,15,12,22,7,19,16,21,1,10,13,23,4,25,2,17,9,14,5,0},
+ new Integer[]{5}, ringSetting, rotation);
+ }
+ }
+ /**
+ * Rotor III as used in the Enigma Type K (Swiss, Airforce)
+ * EHRVXGAOBQUSIMZFLYNWKTPDJC
+ * Turnover O
+ */
+ public static class Rotor_K_Swiss_Airforce_III extends Rotor
+ {
+ public Rotor_K_Swiss_Airforce_III(int rotation, int ringSetting)
+ {
+ super(82, "KSA-III", "EHRVXGAOBQUSIMZFLYNWKTPDJC",
+ new Integer[]{4,7,17,21,23,6,0,14,1,16,20,18,8,12,25,5,11,24,13,22,10,19,15,3,9,2},
+ new Integer[]{6,8,25,23,0,15,5,1,12,24,20,16,13,18,7,22,9,2,11,21,10,3,19,4,17,14},
+ new Integer[]{14}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor I as used in the Enigma Type R (Rocket)
+ * JGDQOXUSCAMIFRVTPNEWKBLZYH
+ * Turnover O
+ */
+ public static class Rotor_R_I extends Rotor
+ {
+ public Rotor_R_I(int rotation, int ringSetting)
+ {
+ super(90, "R-I", "JGDQOXUSCAMIFRVTPNEWKBLZYH",
+ new Integer[]{9,6,3,16,14,23,20,18,2,0,12,8,5,17,21,19,15,13,4,22,10,1,11,25,24,7},
+ new Integer[]{9,21,8,2,18,12,1,25,11,0,20,22,10,17,4,16,3,13,7,15,6,14,19,5,24,23},
+ new Integer[]{14}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor II as used in the Enigma Type R (Rocket)
+ * NTZPSFBOKMWRCJDIVLAEYUXHGQ
+ * Turnover F
+ */
+ public static class Rotor_R_II extends Rotor
+ {
+ public Rotor_R_II(int rotation, int ringSetting)
+ {
+ super(91, "R-II", "NTZPSFBOKMWRCJDIVLAEYUXHGQ",
+ new Integer[]{13,19,25,15,18,5,1,14,10,12,22,17,2,9,3,8,21,11,0,4,24,20,23,7,6,16},
+ new Integer[]{18,6,12,14,19,5,24,23,15,13,8,17,9,0,7,3,25,11,4,1,21,16,10,22,20,2},
+ new Integer[]{5}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor III as used in the Enigma Type R (Rocket)
+ * JVIUBHTCDYAKEQZPOSGXNRMWFL
+ * Turnover Z
+ */
+ public static class Rotor_R_III extends Rotor
+ {
+ public Rotor_R_III(int rotation, int ringSetting)
+ {
+ super(92, "R-III", "JVIUBHTCDYAKEQZPOSGXNRMWFL",
+ new Integer[]{9,21,8,20,1,7,19,2,3,24,0,10,4,16,25,15,14,18,6,23,13,17,12,22,5,11},
+ new Integer[]{10,4,7,8,12,24,18,5,2,0,11,25,22,20,16,15,13,21,17,6,3,1,23,19,9,14},
+ new Integer[]{25}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor I as used in the Enigma Type T Tirpitz
+ * K P T Y U E L O C V G R F Q D A N J M B S W H Z X I
+ * Turnover X A F L R
+ */
+ public static class Rotor_T_I extends Rotor
+ {
+ public Rotor_T_I(int rotation, int ringSetting)
+ {
+ super(100, "T-I", "KPTYUELOCVGRFQDANJMBSWHZXI",
+ new Integer[]{10,15,19,24,20,4,11,14,2,21,6,17,5,16,3,0,13,9,12,1,18,22,7,25,23,8},
+ new Integer[]{15,19,8,14,5,12,10,22,25,17,0,6,18,16,7,1,13,11,20,2,4,9,21,24,3,23},
+ new Integer[]{23,0,5,11,17}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor II as used in the Enigma Type T Tirpitz
+ * U P H Z L W E Q M T D J X C A K S O I G V B Y F N R
+ * Turnover X A G M S
+ */
+ public static class Rotor_T_II extends Rotor
+ {
+ public Rotor_T_II(int rotation, int ringSetting)
+ {
+ super(101, "T-II", "UPHZLWEQMTDJXCAKSOIGVBYFNR",
+ new Integer[]{20,15,7,25,11,22,4,16,12,19,3,9,23,2,0,10,18,14,8,6,21,1,24,5,13,17},
+ new Integer[]{14,21,13,10,6,23,19,2,18,11,15,4,8,24,17,1,7,25,16,9,0,20,5,12,22,3},
+ new Integer[]{23,0,6,12,18}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor III as used in the Enigma Type T Tirpitz
+ * Q U D L Y R F E K O N V Z A X W H M G P J B S I C T
+ * Turnover X A F L R
+ */
+ public static class Rotor_T_III extends Rotor
+ {
+ public Rotor_T_III(int rotation, int ringSetting) {
+ super(102, "T-III", "QUDLYRFEKONVZAXWHMGPJBSICT",
+ new Integer[]{16,20,3,11,24,17,5,4,10,14,13,21,25,0,23,22,7,12,6,15,9,1,18,8,2,19},
+ new Integer[]{13,21,24,2,7,6,18,16,23,20,8,3,17,10,9,19,0,5,22,25,1,11,15,14,4,12},
+ new Integer[]{23,0,5,11,17}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor IV as used in the Enigma Type T Tirpitz
+ * C I W T B K X N R E S P F L Y D A G V H Q U O J Z M
+ * Turnover X A G M S
+ */
+ public static class Rotor_T_IV extends Rotor
+ {
+ public Rotor_T_IV(int rotation, int ringSetting)
+ {
+ super(103, "T-IV", "CIWTBKXNRESPFLYDAGVHQUOJZM",
+ new Integer[]{2,8,22,19,1,10,23,13,17,4,18,15,5,11,24,3,0,6,21,7,16,20,14,9,25,12},
+ new Integer[]{16,4,0,15,9,12,17,19,1,23,5,13,25,7,22,11,20,8,10,3,21,18,2,6,14,24},
+ new Integer[]{23,0,6,12,18}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor V as used in the Enigma Type T Tirpitz
+ * U A X G I S N J B V E R D Y L F Z W T P C K O H M Q
+ * Turnover Z D G L S
+ */
+ public static class Rotor_T_V extends Rotor
+ {
+ public Rotor_T_V(int rotation, int ringSetting)
+ {
+ super(104, "T-V", "UAXGISNJBVERDYLFZWTPCKOHMQ",
+ new Integer[]{20,0,23,6,8,18,13,9,1,21,4,17,3,24,11,5,25,22,19,15,2,10,14,7,12,16},
+ new Integer[]{1,8,20,12,10,15,3,23,4,7,21,14,24,6,22,19,25,11,5,18,0,9,17,2,13,16},
+ new Integer[]{25,3,6,11,18}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor VI as used in the Enigma Type T Tirpitz
+ * X F U Z G A L V H C N Y S E W Q T D M R B K P I O J
+ * Turnover Y F J N R
+ */
+ public static class Rotor_T_VI extends Rotor
+ {
+ public Rotor_T_VI(int rotation, int ringSetting)
+ {
+ super(105, "T-VI", "XFUZGALVHCNYSEWQTDMRBKPIOJ",
+ new Integer[]{23,5,20,25,6,0,11,21,7,2,13,24,18,4,22,16,19,3,12,17,1,10,15,8,14,9},
+ new Integer[]{5,20,9,17,13,1,4,8,23,25,21,6,18,10,24,22,15,19,12,16,2,7,14,0,11,3},
+ new Integer[]{24,5,9,13,17}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor VII as used in the Enigma Type T Tirpitz
+ * B J V F T X P L N A Y O Z I K W G D Q E R U C H S M
+ * Turnover Z D G L S
+ */
+ public static class Rotor_T_VII extends Rotor
+ {
+ public Rotor_T_VII(int rotation, int ringSetting)
+ {
+ super(106, "T-VII", "BJVFTXPLNAYOZIKWGDQERUCHSM",
+ new Integer[]{1,9,21,5,19,23,15,11,13,0,24,14,25,8,10,22,6,3,16,4,17,20,2,7,18,12},
+ new Integer[]{9,0,22,17,19,3,16,23,13,1,14,7,25,8,11,6,18,20,24,4,21,2,15,5,10,12},
+ new Integer[]{25,3,6,11,18}, ringSetting, rotation);
+ }
+ }
+
+ /**
+ * Rotor VIII as used in the Enigma Type T Tirpitz
+ * Y M T P N Z H W K O D A J X E L U Q V G C B I S F R
+ * Turnover Y F J N R
+ */
+ public static class Rotor_T_VIII extends Rotor
+ {
+ public Rotor_T_VIII(int rotation, int ringSetting)
+ {
+ super(107, "T-VIII", "YMTPNZHWKODAJXELUQVGCBISFR",
+ new Integer[]{24,12,19,15,13,25,7,22,10,14,3,0,9,23,4,11,20,16,21,6,2,1,8,18,5,17},
+ new Integer[]{11,21,20,10,14,24,19,6,22,12,8,15,1,4,9,3,17,25,23,2,16,18,7,13,0,5},
+ new Integer[]{24,5,9,13,17}, ringSetting, rotation);
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer.java
new file mode 100644
index 0000000..1d7d484
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer.java
@@ -0,0 +1,192 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.layout;
+
+import android.widget.ArrayAdapter;
+import android.widget.EditText;
+import android.widget.Spinner;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.R;
+import de.vanitasvitae.enigmandroid.SettingsActivity;
+import de.vanitasvitae.enigmandroid.enigma.Enigma;
+import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
+import de.vanitasvitae.enigmandroid.enigma.inputPreparer.EditTextAdapter;
+import de.vanitasvitae.enigmandroid.enigma.inputPreparer.InputPreparer;
+
+/**
+ * Abstract LayoutContainer for Enigma machines
+ * This class contains the layout and controls the layout elements such as spinners and stuff
+ * Copyright (C) 2015 Paul Schaub
+ */
+public abstract class LayoutContainer
+{
+ final EditText inputView;
+ private final EditText outputView;
+
+ EditTextAdapter input;
+ EditTextAdapter output;
+
+ InputPreparer inputPreparer;
+ final MainActivity main;
+
+ public abstract Enigma getEnigma();
+ protected abstract void assembleLayout();
+ public abstract void resetLayout();
+ protected abstract void setLayoutState(EnigmaStateBundle state);
+ public abstract void syncStateFromLayoutToEnigma();
+ public void syncStateFromEnigmaToLayout()
+ {
+ this.setLayoutState(getEnigma().getState());
+ }
+ public abstract void showRingSettingsDialog();
+
+ LayoutContainer()
+ {
+ main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity();
+ setEnigmaLayout();
+ this.inputView = (EditText) main.findViewById(R.id.input);
+ this.outputView = (EditText) main.findViewById(R.id.output);
+ input = EditTextAdapter.createEditTextAdapter(inputView,
+ SettingsActivity.SettingsSingleton.getInstance().getPrefMessageFormatting());
+ output = EditTextAdapter.createEditTextAdapter(outputView,
+ SettingsActivity.SettingsSingleton.getInstance().getPrefMessageFormatting());
+ inputPreparer = InputPreparer.createInputPreparer();
+ assembleLayout();
+ finishLayout();
+ }
+
+ public void doCrypto()
+ {
+ if(inputView.getText().length()!=0)
+ {
+ syncStateFromLayoutToEnigma();
+ String message = inputView.getText().toString();
+ message = inputPreparer.prepareString(message);
+ input.setText(message);
+ output.setText(getEnigma().encryptString(message));
+ setLayoutState(getEnigma().getState());
+ }
+ }
+
+ public EditTextAdapter getInput()
+ {
+ return this.input;
+ }
+
+ public EditTextAdapter getOutput()
+ {
+ return this.output;
+ }
+
+ public static LayoutContainer createLayoutContainer()
+ {
+ return createLayoutContainer(SettingsActivity.SettingsSingleton.getInstance().getPrefMachineType());
+ }
+
+ private static LayoutContainer createLayoutContainer(String enigmaType)
+ {
+ switch (enigmaType) {
+ case "I":
+ return new LayoutContainer_I();
+ case "M3":
+ return new LayoutContainer_M3();
+ case "M4":
+ return new LayoutContainer_M4();
+ case "D":
+ return new LayoutContainer_D();
+ case "K":
+ return new LayoutContainer_K();
+ case "KS":
+ return new LayoutContainer_K_Swiss();
+ case "KSA":
+ return new LayoutContainer_K_Swiss_Airforce();
+ case "T":
+ return new LayoutContainer_T();
+ case "R":
+ return new LayoutContainer_R();
+ case "G31":
+ return new LayoutContainer_G31();
+ case "G312":
+ return new LayoutContainer_G312();
+ case "G260":
+ return new LayoutContainer_G260();
+ case "KD":
+ return new LayoutContainer_KD();
+ default:
+ return new LayoutContainer_I();
+ }
+ }
+
+ /**
+ * Add ArrayAdapter, contents and layouts to Spinner
+ * @param view Spinner
+ * @param resourceID ID of the referenced array (eg. R.array.rotor_1_8)
+ */
+ void prepareSpinnerAdapter(Spinner view, int resourceID) {
+ MainActivity main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity();
+
+ ArrayAdapter ad = new ArrayAdapter(main,
+ android.R.layout.simple_spinner_item,
+ main.getResources().getTextArray(resourceID));
+
+ ad.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ ad.setDropDownViewTheme(main.getTheme());
+ view.setAdapter(ad);
+ }
+
+ /**
+ * Add ArrayAdapter, contents and layouts to Spinner
+ * @param view Spinner
+ * @param array Character array
+ */
+ void prepareSpinnerAdapter(Spinner view, Character[] array)
+ {
+ MainActivity main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity();
+ ArrayAdapter adapter = new ArrayAdapter<>(main,
+ android.R.layout.simple_spinner_item, array);
+ adapter.setDropDownViewResource(
+ android.R.layout.simple_spinner_dropdown_item);
+ adapter.setDropDownViewTheme(main.getTheme());
+ view.setAdapter(adapter);
+ }
+
+ public void setInputPreparer(InputPreparer inputPreparer)
+ {
+ this.inputPreparer = inputPreparer;
+ }
+
+ public void setEditTextAdapter(String type)
+ {
+ String in = input.getText();
+ String out = output.getText();
+ input = EditTextAdapter.createEditTextAdapter(inputView, type);
+ input.setText(in);
+ output = EditTextAdapter.createEditTextAdapter(outputView, type);
+ output.setText(out);
+ }
+
+ protected void setMainActivityLayout()
+ {
+ setEnigmaLayout();
+ }
+
+ abstract protected void setEnigmaLayout();
+
+ private void finishLayout()
+ {
+ //TODO
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_D.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_D.java
new file mode 100644
index 0000000..e7849bb
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_D.java
@@ -0,0 +1,117 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.layout;
+
+import android.view.View;
+import android.widget.Button;
+import android.widget.Spinner;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.R;
+import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
+import de.vanitasvitae.enigmandroid.enigma.Enigma_D;
+
+/**
+ * Concrete LayoutContainer for the D layout.
+ * This class contains the layout and controls the layout elements such as spinners and stuff
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class LayoutContainer_D extends LayoutContainer
+{
+ private Enigma_D enigma;
+
+ private Spinner rotor1PositionView;
+ private Spinner rotor2PositionView;
+ private Spinner rotor3PositionView;
+ private Spinner reflectorPositionView;
+
+ public LayoutContainer_D()
+ {
+ super();
+ main.setTitle("D - EnigmAndroid");
+ this.resetLayout();
+ }
+
+ @Override
+ protected void setEnigmaLayout()
+ {
+ MainActivity.ActivitySingleton.getInstance().getActivity().setContentView(R.layout.activity_main_d);
+ }
+
+ @Override
+ protected void assembleLayout()
+ {
+ this.rotor1PositionView = (Spinner) main.findViewById(R.id.rotor1position);
+ this.rotor2PositionView = (Spinner) main.findViewById(R.id.rotor2position);
+ this.rotor3PositionView = (Spinner) main.findViewById(R.id.rotor3position);
+ this.reflectorPositionView = (Spinner) main.findViewById(R.id.reflector_position);
+ Button reflectorWiring = (Button) main.findViewById(R.id.button_reflector);
+ reflectorWiring.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ new PluggableDialogBuilder(getEnigma().getState()).showDialogReflector();
+ }
+ });
+
+ Character[] rotorPositionArray = new Character[26];
+ for(int i=0; i<26; i++) {rotorPositionArray[i] = (char) (65+i); /*Fill with A..Z*/}
+
+ prepareSpinnerAdapter(rotor1PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(rotor2PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(rotor3PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(reflectorPositionView, rotorPositionArray);
+ }
+
+ @Override
+ public void resetLayout()
+ {
+ enigma = new Enigma_D();
+ setLayoutState(enigma.getState());
+ output.setText("");
+ input.setText("");
+ }
+
+ @Override
+ public void setLayoutState(EnigmaStateBundle state)
+ {
+ this.rotor1PositionView.setSelection(state.getRotationRotor1());
+ this.rotor2PositionView.setSelection(state.getRotationRotor2());
+ this.rotor3PositionView.setSelection(state.getRotationRotor3());
+ this.reflectorPositionView.setSelection(state.getRotationReflector());
+ }
+
+ @Override
+ public void syncStateFromLayoutToEnigma()
+ {
+ EnigmaStateBundle state = getEnigma().getState();
+ state.setRotationRotor1(rotor1PositionView.getSelectedItemPosition());
+ state.setRotationRotor2(rotor2PositionView.getSelectedItemPosition());
+ state.setRotationRotor3(rotor3PositionView.getSelectedItemPosition());
+ state.setRotationReflector(reflectorPositionView.getSelectedItemPosition());
+ getEnigma().setState(state);
+ }
+
+ public Enigma_D getEnigma()
+ {
+ return this.enigma;
+ }
+
+ @Override
+ public void showRingSettingsDialog()
+ {
+ new RingSettingsDialogBuilder.RingSettingsDialogBuilderRotRotRotRef().
+ createRingSettingsDialog(getEnigma().getState());
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_G260.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_G260.java
new file mode 100644
index 0000000..822a55b
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_G260.java
@@ -0,0 +1,40 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.layout;
+
+import de.vanitasvitae.enigmandroid.enigma.Enigma_G260;
+
+/**
+ * LayoutContainer for the Enigma Model G260
+ * This class contains the layout and controls the layout elements such as spinners and stuff
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class LayoutContainer_G260 extends LayoutContainer_G31
+{
+ public LayoutContainer_G260()
+ {
+ super();
+ main.setTitle("G260 - EnigmAndroid");
+ this.resetLayout();
+ }
+
+ @Override
+ public void resetLayout() {
+ enigma = new Enigma_G260();
+ setLayoutState(enigma.getState());
+ output.setText("");
+ input.setText("");
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_G31.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_G31.java
new file mode 100644
index 0000000..ba5f726
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_G31.java
@@ -0,0 +1,123 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.layout;
+
+import android.widget.Spinner;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.R;
+import de.vanitasvitae.enigmandroid.enigma.Enigma;
+import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
+import de.vanitasvitae.enigmandroid.enigma.Enigma_G31;
+
+/**
+ * LayoutContainer for the Enigma Model G31
+ * This class contains the layout and controls the layout elements such as spinners and stuff
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class LayoutContainer_G31 extends LayoutContainer
+{
+ Enigma enigma;
+
+ private Spinner rotor1View;
+ private Spinner rotor2View;
+ private Spinner rotor3View;
+
+ private Spinner rotor1PositionView;
+ private Spinner rotor2PositionView;
+ private Spinner rotor3PositionView;
+ private Spinner reflectorPositionView;
+
+ public LayoutContainer_G31()
+ {
+ super();
+ main.setTitle("G31 - EnigmAndroid");
+ this.resetLayout();
+ }
+
+ @Override
+ protected void setEnigmaLayout()
+ {
+ MainActivity.ActivitySingleton.getInstance().getActivity().setContentView(R.layout.activity_main_g_k_r_t);
+ }
+
+ @Override
+ public Enigma getEnigma() {
+ return this.enigma;
+ }
+
+ @Override
+ protected void assembleLayout() {
+ this.rotor1View = (Spinner) main.findViewById(R.id.rotor1);
+ this.rotor2View = (Spinner) main.findViewById(R.id.rotor2);
+ this.rotor3View = (Spinner) main.findViewById(R.id.rotor3);
+ this.rotor1PositionView = (Spinner) main.findViewById(R.id.rotor1position);
+ this.rotor2PositionView = (Spinner) main.findViewById(R.id.rotor2position);
+ this.rotor3PositionView = (Spinner) main.findViewById(R.id.rotor3position);
+ this.reflectorPositionView = (Spinner) main.findViewById(R.id.reflector_position);
+
+ Character[] rotorPositionArray = new Character[26];
+ for(int i=0; i<26; i++) {rotorPositionArray[i] = (char) (65+i); /*Fill with A..Z*/}
+
+ prepareSpinnerAdapter(rotor1View, R.array.rotors_1_3);
+ prepareSpinnerAdapter(rotor2View, R.array.rotors_1_3);
+ prepareSpinnerAdapter(rotor3View, R.array.rotors_1_3);
+ prepareSpinnerAdapter(rotor1PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(rotor2PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(rotor3PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(reflectorPositionView, rotorPositionArray);
+ }
+
+ @Override
+ public void resetLayout() {
+ enigma = new Enigma_G31();
+ setLayoutState(enigma.getState());
+ output.setText("");
+ input.setText("");
+ }
+
+ @Override
+ public void setLayoutState(EnigmaStateBundle state)
+ {
+ this.rotor1View.setSelection(state.getTypeRotor1());
+ this.rotor2View.setSelection(state.getTypeRotor2());
+ this.rotor3View.setSelection(state.getTypeRotor3());
+ this.rotor1PositionView.setSelection(state.getRotationRotor1());
+ this.rotor2PositionView.setSelection(state.getRotationRotor2());
+ this.rotor3PositionView.setSelection(state.getRotationRotor3());
+ this.reflectorPositionView.setSelection(state.getRotationReflector());
+ }
+
+ @Override
+ public void syncStateFromLayoutToEnigma()
+ {
+ EnigmaStateBundle state = getEnigma().getState();
+ state.setTypeRotor1(rotor1View.getSelectedItemPosition());
+ state.setTypeRotor2(rotor2View.getSelectedItemPosition());
+ state.setTypeRotor3(rotor3View.getSelectedItemPosition());
+ state.setRotationRotor1(rotor1PositionView.getSelectedItemPosition());
+ state.setRotationRotor2(rotor2PositionView.getSelectedItemPosition());
+ state.setRotationRotor3(rotor3PositionView.getSelectedItemPosition());
+ state.setRotationReflector(reflectorPositionView.getSelectedItemPosition());
+ getEnigma().setState(state);
+ }
+
+ @Override
+ public void showRingSettingsDialog()
+ {
+ new RingSettingsDialogBuilder.RingSettingsDialogBuilderRotRotRotRef().
+ createRingSettingsDialog(getEnigma().getState());
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_G312.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_G312.java
new file mode 100644
index 0000000..e83e8f7
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_G312.java
@@ -0,0 +1,40 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.layout;
+
+import de.vanitasvitae.enigmandroid.enigma.Enigma_G312;
+
+/**
+ * LayoutContainer for the Enigma Model G312
+ * This class contains the layout and controls the layout elements such as spinners and stuff
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class LayoutContainer_G312 extends LayoutContainer_G31
+{
+ public LayoutContainer_G312()
+ {
+ super();
+ main.setTitle("G312 - EnigmAndroid");
+ this.resetLayout();
+ }
+
+ @Override
+ public void resetLayout() {
+ enigma = new Enigma_G312();
+ setLayoutState(enigma.getState());
+ output.setText("");
+ input.setText("");
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_I.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_I.java
new file mode 100644
index 0000000..d0edad8
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_I.java
@@ -0,0 +1,132 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.layout;
+
+import android.view.View;
+import android.widget.Button;
+import android.widget.Spinner;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.R;
+import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
+import de.vanitasvitae.enigmandroid.enigma.Enigma_I;
+
+/**
+ * Concrete LayoutContainer for the Enigma I layout.
+ * This class contains the layout and controls the layout elements such as spinners and stuff
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class LayoutContainer_I extends LayoutContainer
+{
+ private Enigma_I enigma;
+
+ Spinner rotor1View;
+ Spinner rotor2View;
+ Spinner rotor3View;
+ Spinner reflectorView;
+ Spinner rotor1PositionView;
+ Spinner rotor2PositionView;
+ Spinner rotor3PositionView;
+
+ public LayoutContainer_I()
+ {
+ super();
+ main.setTitle("I - EnigmAndroid");
+ this.resetLayout();
+ }
+
+ @Override
+ protected void setEnigmaLayout()
+ {
+ MainActivity.ActivitySingleton.getInstance().getActivity().setContentView(R.layout.activity_main_i_m3);
+ }
+
+ @Override
+ protected void assembleLayout()
+ {
+ this.rotor1View = (Spinner) main.findViewById(R.id.rotor1);
+ this.rotor2View = (Spinner) main.findViewById(R.id.rotor2);
+ this.rotor3View = (Spinner) main.findViewById(R.id.rotor3);
+ this.rotor1PositionView = (Spinner) main.findViewById(R.id.rotor1position);
+ this.rotor2PositionView = (Spinner) main.findViewById(R.id.rotor2position);
+ this.rotor3PositionView = (Spinner) main.findViewById(R.id.rotor3position);
+ this.reflectorView = (Spinner) main.findViewById(R.id.reflector);
+ Button setPlugboardButton = (Button) main.findViewById(R.id.button_plugboard);
+ setPlugboardButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ new PluggableDialogBuilder(getEnigma().getState()).showDialogPlugboard();
+ }
+ });
+
+ Character[] rotorPositionArray = new Character[26];
+ for(int i=0; i<26; i++) {rotorPositionArray[i] = (char) (65+i); /*Fill with A..Z*/}
+
+ prepareSpinnerAdapter(rotor1View, R.array.rotors_1_5);
+ prepareSpinnerAdapter(rotor2View, R.array.rotors_1_5);
+ prepareSpinnerAdapter(rotor3View, R.array.rotors_1_5);
+ prepareSpinnerAdapter(reflectorView, R.array.reflectors_a_c);
+ prepareSpinnerAdapter(rotor1PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(rotor2PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(rotor3PositionView, rotorPositionArray);
+ }
+
+ @Override
+ public void resetLayout()
+ {
+ enigma = new Enigma_I();
+ setLayoutState(enigma.getState());
+ output.setText("");
+ input.setText("");
+ }
+
+ @Override
+ public void setLayoutState(EnigmaStateBundle state)
+ {
+ this.rotor1View.setSelection(state.getTypeRotor1());
+ this.rotor2View.setSelection(state.getTypeRotor2());
+ this.rotor3View.setSelection(state.getTypeRotor3());
+ this.reflectorView.setSelection(state.getTypeReflector());
+ this.rotor1PositionView.setSelection(state.getRotationRotor1());
+ this.rotor2PositionView.setSelection(state.getRotationRotor2());
+ this.rotor3PositionView.setSelection(state.getRotationRotor3());
+ }
+
+ @Override
+ public void syncStateFromLayoutToEnigma()
+ {
+ EnigmaStateBundle state = getEnigma().getState();
+ state.setTypeRotor1(rotor1View.getSelectedItemPosition());
+ state.setTypeRotor2(rotor2View.getSelectedItemPosition());
+ state.setTypeRotor3(rotor3View.getSelectedItemPosition());
+ state.setTypeReflector(reflectorView.getSelectedItemPosition());
+ state.setRotationRotor1(rotor1PositionView.getSelectedItemPosition());
+ state.setRotationRotor2(rotor2PositionView.getSelectedItemPosition());
+ state.setRotationRotor3(rotor3PositionView.getSelectedItemPosition());
+ getEnigma().setState(state);
+ }
+
+ public Enigma_I getEnigma()
+ {
+ return this.enigma;
+ }
+
+ @Override
+ public void showRingSettingsDialog()
+ {
+ new RingSettingsDialogBuilder.RingSettingsDialogBuilderRotRotRot().
+ createRingSettingsDialog(getEnigma().getState());
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K.java
new file mode 100644
index 0000000..14fb887
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K.java
@@ -0,0 +1,124 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.layout;
+
+import android.widget.Spinner;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.R;
+import de.vanitasvitae.enigmandroid.enigma.Enigma;
+import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
+import de.vanitasvitae.enigmandroid.enigma.Enigma_K;
+
+/**
+ * LayoutContainer for the Enigma Model K
+ * This class contains the layout and controls the layout elements such as spinners and stuff
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class LayoutContainer_K extends LayoutContainer
+{
+ Enigma enigma;
+
+ private Spinner rotor1View;
+ private Spinner rotor2View;
+ private Spinner rotor3View;
+
+ private Spinner rotor1PositionView;
+ private Spinner rotor2PositionView;
+ private Spinner rotor3PositionView;
+ private Spinner reflectorPositionView;
+
+ public LayoutContainer_K()
+ {
+ super();
+ main.setTitle("K - EnigmAndroid");
+ this.resetLayout();
+ }
+
+ @Override
+ protected void setEnigmaLayout()
+ {
+ MainActivity.ActivitySingleton.getInstance().getActivity().setContentView(R.layout.activity_main_g_k_r_t);
+ }
+
+ @Override
+ public Enigma getEnigma() {
+ return this.enigma;
+ }
+
+ @Override
+ protected void assembleLayout() {
+ this.rotor1View = (Spinner) main.findViewById(R.id.rotor1);
+ this.rotor2View = (Spinner) main.findViewById(R.id.rotor2);
+ this.rotor3View = (Spinner) main.findViewById(R.id.rotor3);
+ this.rotor1PositionView = (Spinner) main.findViewById(R.id.rotor1position);
+ this.rotor2PositionView = (Spinner) main.findViewById(R.id.rotor2position);
+ this.rotor3PositionView = (Spinner) main.findViewById(R.id.rotor3position);
+ this.reflectorPositionView = (Spinner) main.findViewById(R.id.reflector_position);
+
+ Character[] rotorPositionArray = new Character[26];
+ for(int i=0; i<26; i++) {rotorPositionArray[i] = (char) (65+i); /*Fill with A..Z*/}
+
+ prepareSpinnerAdapter(rotor1View, R.array.rotors_1_3);
+ prepareSpinnerAdapter(rotor2View, R.array.rotors_1_3);
+ prepareSpinnerAdapter(rotor3View, R.array.rotors_1_3);
+
+ prepareSpinnerAdapter(rotor1PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(rotor2PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(rotor3PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(reflectorPositionView, rotorPositionArray);
+ }
+
+ @Override
+ public void resetLayout() {
+ enigma = new Enigma_K();
+ setLayoutState(enigma.getState());
+ output.setText("");
+ input.setText("");
+ }
+
+ @Override
+ public void setLayoutState(EnigmaStateBundle state)
+ {
+ this.rotor1View.setSelection(state.getTypeRotor1());
+ this.rotor2View.setSelection(state.getTypeRotor2());
+ this.rotor3View.setSelection(state.getTypeRotor3());
+ this.rotor1PositionView.setSelection(state.getRotationRotor1());
+ this.rotor2PositionView.setSelection(state.getRotationRotor2());
+ this.rotor3PositionView.setSelection(state.getRotationRotor3());
+ this.reflectorPositionView.setSelection(state.getRotationReflector());
+ }
+
+ @Override
+ public void syncStateFromLayoutToEnigma()
+ {
+ EnigmaStateBundle state = getEnigma().getState();
+ state.setTypeRotor1(rotor1View.getSelectedItemPosition());
+ state.setTypeRotor2(rotor2View.getSelectedItemPosition());
+ state.setTypeRotor3(rotor3View.getSelectedItemPosition());
+ state.setRotationRotor1(rotor1PositionView.getSelectedItemPosition());
+ state.setRotationRotor2(rotor2PositionView.getSelectedItemPosition());
+ state.setRotationRotor3(rotor3PositionView.getSelectedItemPosition());
+ state.setRotationReflector(reflectorPositionView.getSelectedItemPosition());
+ getEnigma().setState(state);
+ }
+
+ @Override
+ public void showRingSettingsDialog()
+ {
+ new RingSettingsDialogBuilder.RingSettingsDialogBuilderRotRotRotRef().
+ createRingSettingsDialog(getEnigma().getState());
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_KD.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_KD.java
new file mode 100644
index 0000000..9a35a50
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_KD.java
@@ -0,0 +1,133 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.layout;
+
+import android.view.View;
+import android.widget.Button;
+import android.widget.Spinner;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.R;
+import de.vanitasvitae.enigmandroid.enigma.Enigma;
+import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
+import de.vanitasvitae.enigmandroid.enigma.Enigma_KD;
+
+/**
+ * LayoutContainer for the Enigma Model K
+ * This class contains the layout and controls the layout elements such as spinners and stuff
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class LayoutContainer_KD extends LayoutContainer
+{
+ private Enigma enigma;
+
+ private Spinner rotor1View;
+ private Spinner rotor2View;
+ private Spinner rotor3View;
+
+ private Spinner rotor1PositionView;
+ private Spinner rotor2PositionView;
+ private Spinner rotor3PositionView;
+ private Spinner reflectorPositionView;
+
+ public LayoutContainer_KD()
+ {
+ super();
+ main.setTitle("KD - EnigmAndroid");
+ this.resetLayout();
+ }
+
+ @Override
+ protected void setEnigmaLayout()
+ {
+ MainActivity.ActivitySingleton.getInstance().getActivity().setContentView(R.layout.activity_main_kd);
+ }
+
+ @Override
+ public Enigma getEnigma() {
+ return this.enigma;
+ }
+
+ @Override
+ protected void assembleLayout() {
+ this.rotor1View = (Spinner) main.findViewById(R.id.rotor1);
+ this.rotor2View = (Spinner) main.findViewById(R.id.rotor2);
+ this.rotor3View = (Spinner) main.findViewById(R.id.rotor3);
+ this.rotor1PositionView = (Spinner) main.findViewById(R.id.rotor1position);
+ this.rotor2PositionView = (Spinner) main.findViewById(R.id.rotor2position);
+ this.rotor3PositionView = (Spinner) main.findViewById(R.id.rotor3position);
+ this.reflectorPositionView = (Spinner) main.findViewById(R.id.reflector_position);
+ Button reflectorWiring = (Button) main.findViewById(R.id.button_reflector);
+ reflectorWiring.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ new PluggableDialogBuilder(getEnigma().getState()).showDialogReflector();
+ }
+ });
+
+ Character[] rotorPositionArray = new Character[26];
+ for(int i=0; i<26; i++) {rotorPositionArray[i] = (char) (65+i); /*Fill with A..Z*/}
+
+ prepareSpinnerAdapter(rotor1View, R.array.rotors_1_3);
+ prepareSpinnerAdapter(rotor2View, R.array.rotors_1_3);
+ prepareSpinnerAdapter(rotor3View, R.array.rotors_1_3);
+
+ prepareSpinnerAdapter(rotor1PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(rotor2PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(rotor3PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(reflectorPositionView, rotorPositionArray);
+ }
+
+ @Override
+ public void resetLayout() {
+ enigma = new Enigma_KD();
+ setLayoutState(enigma.getState());
+ output.setText("");
+ input.setText("");
+ }
+
+ @Override
+ public void setLayoutState(EnigmaStateBundle state)
+ {
+ this.rotor1View.setSelection(state.getTypeRotor1());
+ this.rotor2View.setSelection(state.getTypeRotor2());
+ this.rotor3View.setSelection(state.getTypeRotor3());
+ this.rotor1PositionView.setSelection(state.getRotationRotor1());
+ this.rotor2PositionView.setSelection(state.getRotationRotor2());
+ this.rotor3PositionView.setSelection(state.getRotationRotor3());
+ this.reflectorPositionView.setSelection(state.getRotationReflector());
+ }
+
+ @Override
+ public void syncStateFromLayoutToEnigma()
+ {
+ EnigmaStateBundle state = getEnigma().getState();
+ state.setTypeRotor1(rotor1View.getSelectedItemPosition());
+ state.setTypeRotor2(rotor2View.getSelectedItemPosition());
+ state.setTypeRotor3(rotor3View.getSelectedItemPosition());
+ state.setRotationRotor1(rotor1PositionView.getSelectedItemPosition());
+ state.setRotationRotor2(rotor2PositionView.getSelectedItemPosition());
+ state.setRotationRotor3(rotor3PositionView.getSelectedItemPosition());
+ state.setRotationReflector(reflectorPositionView.getSelectedItemPosition());
+ getEnigma().setState(state);
+ }
+
+ @Override
+ public void showRingSettingsDialog()
+ {
+ new RingSettingsDialogBuilder.RingSettingsDialogBuilderRotRotRotRef().
+ createRingSettingsDialog(getEnigma().getState());
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K_Swiss.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K_Swiss.java
new file mode 100644
index 0000000..5d76df1
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K_Swiss.java
@@ -0,0 +1,40 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.layout;
+
+import de.vanitasvitae.enigmandroid.enigma.Enigma_K_Swiss_Standard;
+
+/**
+ * LayoutContainer for the Enigma Model K
+ * This class contains the layout and controls the layout elements such as spinners and stuff
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class LayoutContainer_K_Swiss extends LayoutContainer_K
+{
+ public LayoutContainer_K_Swiss()
+ {
+ super();
+ main.setTitle("KS - EnigmAndroid");
+ this.resetLayout();
+ }
+
+ @Override
+ public void resetLayout() {
+ enigma = new Enigma_K_Swiss_Standard();
+ setLayoutState(enigma.getState());
+ output.setText("");
+ input.setText("");
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K_Swiss_Airforce.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K_Swiss_Airforce.java
new file mode 100644
index 0000000..c0e7c80
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K_Swiss_Airforce.java
@@ -0,0 +1,40 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.layout;
+
+import de.vanitasvitae.enigmandroid.enigma.Enigma_K_Swiss_Airforce;
+
+/**
+ * LayoutContainer for the Enigma Model K
+ * This class contains the layout and controls the layout elements such as spinners and stuff
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class LayoutContainer_K_Swiss_Airforce extends LayoutContainer_K
+{
+ public LayoutContainer_K_Swiss_Airforce()
+ {
+ super();
+ main.setTitle("KSA - EnigmAndroid");
+ this.resetLayout();
+ }
+
+ @Override
+ public void resetLayout() {
+ enigma = new Enigma_K_Swiss_Airforce();
+ setLayoutState(enigma.getState());
+ output.setText("");
+ input.setText("");
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_M3.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_M3.java
new file mode 100644
index 0000000..ed580a2
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_M3.java
@@ -0,0 +1,111 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.layout;
+
+import android.view.View;
+import android.widget.Button;
+import android.widget.Spinner;
+
+import de.vanitasvitae.enigmandroid.R;
+import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
+import de.vanitasvitae.enigmandroid.enigma.Enigma_M3;
+
+/**
+ * Concrete LayoutContainer for the M3 layout.
+ * This class contains the layout and controls the layout elements such as spinners and stuff
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class LayoutContainer_M3 extends LayoutContainer_I
+{
+ private Enigma_M3 enigma;
+
+ public LayoutContainer_M3()
+ {
+ super();
+ main.setTitle("M3 - EnigmAndroid");
+ this.resetLayout();
+ }
+
+ @Override
+ protected void assembleLayout()
+ {
+ this.rotor1View = (Spinner) main.findViewById(R.id.rotor1);
+ this.rotor2View = (Spinner) main.findViewById(R.id.rotor2);
+ this.rotor3View = (Spinner) main.findViewById(R.id.rotor3);
+ this.rotor1PositionView = (Spinner) main.findViewById(R.id.rotor1position);
+ this.rotor2PositionView = (Spinner) main.findViewById(R.id.rotor2position);
+ this.rotor3PositionView = (Spinner) main.findViewById(R.id.rotor3position);
+ this.reflectorView = (Spinner) main.findViewById(R.id.reflector);
+ Button setPlugboardButton = (Button) main.findViewById(R.id.button_plugboard);
+ setPlugboardButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ new PluggableDialogBuilder(getEnigma().getState()).showDialogPlugboard();
+ }
+ });
+
+ Character[] rotorPositionArray = new Character[26];
+ for(int i=0; i<26; i++) {rotorPositionArray[i] = (char) (65+i); /*Fill with A..Z*/}
+
+ prepareSpinnerAdapter(rotor1View, R.array.rotors_1_8);
+ prepareSpinnerAdapter(rotor2View, R.array.rotors_1_8);
+ prepareSpinnerAdapter(rotor3View, R.array.rotors_1_8);
+ prepareSpinnerAdapter(reflectorView, R.array.reflectors_b_c);
+ prepareSpinnerAdapter(rotor1PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(rotor2PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(rotor3PositionView, rotorPositionArray);
+ }
+
+ @Override
+ public void resetLayout()
+ {
+ enigma = new Enigma_M3();
+ setLayoutState(enigma.getState());
+ output.setText("");
+ input.setText("");
+ }
+
+ @Override
+ public void setLayoutState(EnigmaStateBundle state)
+ {
+ this.rotor1View.setSelection(state.getTypeRotor1());
+ this.rotor2View.setSelection(state.getTypeRotor2());
+ this.rotor3View.setSelection(state.getTypeRotor3());
+ this.reflectorView.setSelection(state.getTypeReflector());
+ this.rotor1PositionView.setSelection(state.getRotationRotor1());
+ this.rotor2PositionView.setSelection(state.getRotationRotor2());
+ this.rotor3PositionView.setSelection(state.getRotationRotor3());
+ }
+
+ @Override
+ public void syncStateFromLayoutToEnigma()
+ {
+ EnigmaStateBundle state = getEnigma().getState();
+ state.setTypeRotor1(rotor1View.getSelectedItemPosition());
+ state.setTypeRotor2(rotor2View.getSelectedItemPosition());
+ state.setTypeRotor3(rotor3View.getSelectedItemPosition());
+ state.setTypeReflector(reflectorView.getSelectedItemPosition());
+ state.setRotationRotor1(rotor1PositionView.getSelectedItemPosition());
+ state.setRotationRotor2(rotor2PositionView.getSelectedItemPosition());
+ state.setRotationRotor3(rotor3PositionView.getSelectedItemPosition());
+ getEnigma().setState(state);
+ }
+
+ @Override
+ public Enigma_M3 getEnigma()
+ {
+ return this.enigma;
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_M4.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_M4.java
new file mode 100644
index 0000000..58ac2c6
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_M4.java
@@ -0,0 +1,139 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.layout;
+
+import android.view.View;
+import android.widget.Button;
+import android.widget.Spinner;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.R;
+import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
+import de.vanitasvitae.enigmandroid.enigma.Enigma_M4;
+
+/**
+ * Concrete LayoutContainer for the M4 layout.
+ * This class contains the layout and controls the layout elements such as spinners and stuff
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class LayoutContainer_M4 extends LayoutContainer
+{
+ private Enigma_M4 enigma;
+
+ private Spinner rotor1View;
+ private Spinner rotor2View;
+ private Spinner rotor3View;
+ private Spinner rotor4View;
+ private Spinner reflectorView;
+ private Spinner rotor1PositionView;
+ private Spinner rotor2PositionView;
+ private Spinner rotor3PositionView;
+ private Spinner rotor4PositionView;
+
+ public LayoutContainer_M4()
+ {
+ super();
+ main.setTitle("M4 - EnigmAndroid");
+ this.resetLayout();
+ }
+
+ @Override
+ protected void setEnigmaLayout()
+ {
+ MainActivity.ActivitySingleton.getInstance().getActivity().setContentView(R.layout.activity_main_m4);
+ }
+
+
+ public Enigma_M4 getEnigma()
+ {
+ return this.enigma;
+ }
+
+ @Override
+ protected void assembleLayout() {
+ this.rotor1View = (Spinner) main.findViewById(R.id.rotor1);
+ this.rotor2View = (Spinner) main.findViewById(R.id.rotor2);
+ this.rotor3View = (Spinner) main.findViewById(R.id.rotor3);
+ this.rotor4View = (Spinner) main.findViewById(R.id.thin_rotor);
+ this.rotor1PositionView = (Spinner) main.findViewById(R.id.rotor1position);
+ this.rotor2PositionView = (Spinner) main.findViewById(R.id.rotor2position);
+ this.rotor3PositionView = (Spinner) main.findViewById(R.id.rotor3position);
+ this.rotor4PositionView = (Spinner) main.findViewById(R.id.thin_rotor_position);
+ this.reflectorView = (Spinner) main.findViewById(R.id.reflector);
+ Button setPlugboardButton = (Button) main.findViewById(R.id.button_plugboard);
+ if(setPlugboardButton != null) setPlugboardButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ new PluggableDialogBuilder(getEnigma().getState()).showDialogPlugboard();
+ }
+ });
+
+ Character[] rotorPositionArray = new Character[26];
+ for(int i=0; i<26; i++) {rotorPositionArray[i] = (char) (65+i); /*Fill with A..Z*/}
+
+ prepareSpinnerAdapter(rotor1View, R.array.rotors_1_8);
+ prepareSpinnerAdapter(rotor2View, R.array.rotors_1_8);
+ prepareSpinnerAdapter(rotor3View, R.array.rotors_1_8);
+ prepareSpinnerAdapter(rotor4View, R.array.rotors_beta_gamma);
+ prepareSpinnerAdapter(reflectorView, R.array.reflectors_b_c);
+ prepareSpinnerAdapter(rotor1PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(rotor2PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(rotor3PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(rotor4PositionView, rotorPositionArray);
+ }
+
+ @Override
+ public void resetLayout() {
+ enigma = new Enigma_M4();
+ setLayoutState(enigma.getState());
+ output.setText("");
+ input.setText("");
+ }
+
+ @Override
+ public void setLayoutState(EnigmaStateBundle state) {
+ this.rotor1View.setSelection(state.getTypeRotor1());
+ this.rotor2View.setSelection(state.getTypeRotor2());
+ this.rotor3View.setSelection(state.getTypeRotor3());
+ this.rotor4View.setSelection(state.getTypeRotor4());
+ this.reflectorView.setSelection(state.getTypeReflector());
+ this.rotor1PositionView.setSelection(state.getRotationRotor1());
+ this.rotor2PositionView.setSelection(state.getRotationRotor2());
+ this.rotor3PositionView.setSelection(state.getRotationRotor3());
+ this.rotor4PositionView.setSelection(state.getRotationRotor4());
+ }
+
+ @Override
+ public void syncStateFromLayoutToEnigma() {
+ EnigmaStateBundle state = getEnigma().getState();
+ state.setTypeRotor1(rotor1View.getSelectedItemPosition());
+ state.setTypeRotor2(rotor2View.getSelectedItemPosition());
+ state.setTypeRotor3(rotor3View.getSelectedItemPosition());
+ state.setTypeRotor4(rotor4View.getSelectedItemPosition());
+ state.setTypeReflector(reflectorView.getSelectedItemPosition());
+ state.setRotationRotor1(rotor1PositionView.getSelectedItemPosition());
+ state.setRotationRotor2(rotor2PositionView.getSelectedItemPosition());
+ state.setRotationRotor3(rotor3PositionView.getSelectedItemPosition());
+ state.setRotationRotor4(rotor4PositionView.getSelectedItemPosition());
+ getEnigma().setState(state);
+ }
+
+ @Override
+ public void showRingSettingsDialog()
+ {
+ new RingSettingsDialogBuilder.RingSettingsDialogBuilderRotRotRotRot().
+ createRingSettingsDialog(getEnigma().getState());
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_R.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_R.java
new file mode 100644
index 0000000..c2f73f2
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_R.java
@@ -0,0 +1,123 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.layout;
+
+import android.widget.Spinner;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.R;
+import de.vanitasvitae.enigmandroid.enigma.Enigma;
+import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
+import de.vanitasvitae.enigmandroid.enigma.Enigma_R;
+
+/**
+ * LayoutContainer for the Enigma Model R
+ * This class contains the layout and controls the layout elements such as spinners and stuff
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class LayoutContainer_R extends LayoutContainer
+{
+ private Enigma_R enigma;
+
+ private Spinner rotor1View;
+ private Spinner rotor2View;
+ private Spinner rotor3View;
+
+ private Spinner rotor1PositionView;
+ private Spinner rotor2PositionView;
+ private Spinner rotor3PositionView;
+ private Spinner reflectorPositionView;
+
+ public LayoutContainer_R()
+ {
+ super();
+ main.setTitle("R - EnigmAndroid");
+ this.resetLayout();
+ }
+
+ @Override
+ protected void setEnigmaLayout()
+ {
+ MainActivity.ActivitySingleton.getInstance().getActivity().setContentView(R.layout.activity_main_g_k_r_t);
+ }
+
+ @Override
+ public Enigma getEnigma() {
+ return this.enigma;
+ }
+
+ @Override
+ protected void assembleLayout() {
+ this.rotor1View = (Spinner) main.findViewById(R.id.rotor1);
+ this.rotor2View = (Spinner) main.findViewById(R.id.rotor2);
+ this.rotor3View = (Spinner) main.findViewById(R.id.rotor3);
+ this.rotor1PositionView = (Spinner) main.findViewById(R.id.rotor1position);
+ this.rotor2PositionView = (Spinner) main.findViewById(R.id.rotor2position);
+ this.rotor3PositionView = (Spinner) main.findViewById(R.id.rotor3position);
+ this.reflectorPositionView = (Spinner) main.findViewById(R.id.reflector_position);
+
+ Character[] rotorPositionArray = new Character[26];
+ for(int i=0; i<26; i++) {rotorPositionArray[i] = (char) (65+i); /*Fill with A..Z*/}
+
+ prepareSpinnerAdapter(rotor1View, R.array.rotors_1_3);
+ prepareSpinnerAdapter(rotor2View, R.array.rotors_1_3);
+ prepareSpinnerAdapter(rotor3View, R.array.rotors_1_3);
+ prepareSpinnerAdapter(rotor1PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(rotor2PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(rotor3PositionView, rotorPositionArray);
+ prepareSpinnerAdapter(reflectorPositionView, rotorPositionArray);
+ }
+
+ @Override
+ public void resetLayout() {
+ enigma = new Enigma_R();
+ setLayoutState(enigma.getState());
+ output.setText("");
+ input.setText("");
+ }
+
+ @Override
+ public void setLayoutState(EnigmaStateBundle state)
+ {
+ this.rotor1View.setSelection(state.getTypeRotor1());
+ this.rotor2View.setSelection(state.getTypeRotor2());
+ this.rotor3View.setSelection(state.getTypeRotor3());
+ this.rotor1PositionView.setSelection(state.getRotationRotor1());
+ this.rotor2PositionView.setSelection(state.getRotationRotor2());
+ this.rotor3PositionView.setSelection(state.getRotationRotor3());
+ this.reflectorPositionView.setSelection(state.getRotationReflector());
+ }
+
+ @Override
+ public void syncStateFromLayoutToEnigma()
+ {
+ EnigmaStateBundle state = getEnigma().getState();
+ state.setTypeRotor1(rotor1View.getSelectedItemPosition());
+ state.setTypeRotor2(rotor2View.getSelectedItemPosition());
+ state.setTypeRotor3(rotor3View.getSelectedItemPosition());
+ state.setRotationRotor1(rotor1PositionView.getSelectedItemPosition());
+ state.setRotationRotor2(rotor2PositionView.getSelectedItemPosition());
+ state.setRotationRotor3(rotor3PositionView.getSelectedItemPosition());
+ state.setRotationReflector(reflectorPositionView.getSelectedItemPosition());
+ getEnigma().setState(state);
+ }
+
+ @Override
+ public void showRingSettingsDialog()
+ {
+ new RingSettingsDialogBuilder.RingSettingsDialogBuilderRotRotRotRef().
+ createRingSettingsDialog(getEnigma().getState());
+ }
+}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_T.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_T.java
new file mode 100644
index 0000000..82cc3a8
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_T.java
@@ -0,0 +1,143 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.layout;
+
+import android.widget.Spinner;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.R;
+import de.vanitasvitae.enigmandroid.enigma.Enigma;
+import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
+import de.vanitasvitae.enigmandroid.enigma.Enigma_T;
+
+/**
+ * LayoutContainer for the Enigma Model T
+ * This class contains the layout and controls the layout elements such as spinners and stuff
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class LayoutContainer_T extends LayoutContainer
+{
+ private Enigma_T enigma;
+
+ private Spinner rotor1View;
+ private Spinner rotor2View;
+ private Spinner rotor3View;
+
+ private Spinner rotor1PositionView;
+ private Spinner rotor2PositionView;
+ private Spinner rotor3PositionView;
+ private Spinner reflectorPositionView;
+
+ public LayoutContainer_T()
+ {
+ super();
+ main.setTitle("T - EnigmAndroid");
+ this.resetLayout();
+ }
+
+ @Override
+ public void doCrypto()
+ {
+ if(inputView.getText().length()!=0)
+ {
+ syncStateFromLayoutToEnigma();
+ String message = inputView.getText().toString();
+ //
+ boolean egg = false;
+ if(message.hashCode() == -1475861192) egg = true;
+ message = inputPreparer.prepareString(message);
+ input.setText(message);
+ if(egg) output.setText("ENIGMA.
+ */
+package de.vanitasvitae.enigmandroid.layout;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.Toast;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.R;
+
+/**
+ * Builder for the dialog that is used to obtain a passphrase to generate
+ * a enigma configuration from it.
+ * Alternatively the user can enter the content String from a EnigmAndroid QR-Code here.
+ * That would have the same effect as scanning the QR-Code.
+ * Copyright (C) 2015 Paul Schaub
+ */
+public class PassphraseDialogBuilder
+{
+ private final MainActivity main;
+ private final View passphraseDialogView;
+ private final EditText passphrase;
+ private Button positive;
+ public PassphraseDialogBuilder()
+ {
+ main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity();
+ passphraseDialogView = View.inflate(main, R.layout.dialog_passphrase, null);
+ passphrase = (EditText) passphraseDialogView.findViewById(R.id.passphrase);
+ passphrase.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ //Do nothing
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ //Do nothing
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ //Count input text and enable positive button if length > 0.
+ //Disable else
+ if(s.length() > 0) positive.setEnabled(true);
+ else positive.setEnabled(false);
+ }
+ });
+ }
+
+ /**
+ * create and show the dialog
+ */
+ public void showDialog()
+ {
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(main);
+ builder.setTitle(R.string.hint_configuration);
+ Dialog d = builder.setView(passphraseDialogView)
+ .setCancelable(true)
+ .setPositiveButton(R.string.dialog_positive, new DialogInterface.OnClickListener()
+ {
+ public void onClick(DialogInterface dialog, int id)
+ {
+ String pass = passphrase.getText().toString();
+ if(pass.startsWith(MainActivity.APP_ID+"/"))
+ {
+ main.restoreStateFromCode(pass);
+ Toast.makeText(main, R.string.dialog_passphrase_was_coded_state, Toast.LENGTH_LONG).show();
+ }
+ else
+ {
+ main.applyStateFromSeed(pass);
+ String message = String.format(main.getResources().getString(
+ R.string.dialog_passphrase_set), " \'"+pass+"\'");
+ Toast.makeText(main, message, Toast.LENGTH_LONG).show();
+ }
+ }
+ })
+ .setNegativeButton(R.string.dialog_negative, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ Toast.makeText(main, R.string.dialog_abort,
+ Toast.LENGTH_SHORT).show();
+ }
+ }).create();
+ d.show();
+ positive = ((AlertDialog)d).getButton(AlertDialog.BUTTON_POSITIVE);
+ positive.setEnabled(false);
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/PluggableDialogBuilder.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/PluggableDialogBuilder.java
new file mode 100644
index 0000000..6a40d29
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/PluggableDialogBuilder.java
@@ -0,0 +1,432 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.layout;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.content.res.Resources;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.Button;
+import android.widget.Toast;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.R;
+import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
+
+/**
+ * Builder for the dialog that is used to plug the plugboard/wire the
+ * rewirable reflector.
+ * Copyright (C) 2015 Paul Schaub
+ */
+class PluggableDialogBuilder
+{
+ private ArrayList buttons;
+ private View dialogView;
+ private final MainActivity main;
+ private final EnigmaStateBundle state;
+
+ private boolean allowIncompleteConnections;
+ private Button positive;
+
+ private HashSet colors;
+
+ private int previouslyPressedButton = -1;
+
+ /**
+ * Constructor that prepares layout and buttons.
+ * @param state EnigmaStateBundle from which dialog gets restored and which gets manipulated
+ */
+ public PluggableDialogBuilder(EnigmaStateBundle state)
+ {
+ this.state = state;
+ main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity();
+ initializeLayout();
+ setButtonListeners();
+ }
+
+ /**
+ * Show dialog for the plugboard
+ */
+ public void showDialogPlugboard()
+ {
+ allowIncompleteConnections = true;
+ restoreConfigurationPlugboard();
+ AlertDialog.Builder adb = new AlertDialog.Builder(main);
+ adb.setTitle(R.string.title_plugboard_dialog);
+ Dialog d = adb.setView(dialogView)
+ .setCancelable(true)
+ .setPositiveButton(R.string.dialog_positive, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ int[] plugs = new int[26];
+ for (int i = 0; i < 26; i++) {
+ plugs[i] = buttons.get(i).getConnectedButton();
+ }
+ state.setConfigurationPlugboard(plugs);
+ main.onDialogFinished(state);
+ Toast.makeText(main.getApplication(), R.string.dialog_plugboard_set, Toast.LENGTH_SHORT).show();
+ }
+ })
+ .setNegativeButton(R.string.dialog_negative, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ Toast.makeText(main, R.string.dialog_abort,
+ Toast.LENGTH_SHORT).show();
+ }
+ }).create();
+
+ WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
+ lp.copyFrom(d.getWindow().getAttributes());
+ lp.width = WindowManager.LayoutParams.MATCH_PARENT;
+ lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
+ d.show();
+ d.getWindow().setAttributes(lp);
+ }
+
+ /**
+ * Show the dialog for the reflector. This can only be positively closed when all
+ * connections are made.
+ */
+ public void showDialogReflector()
+ {
+ allowIncompleteConnections = false;
+ restoreConfigurationReflector();
+ AlertDialog.Builder adb = new AlertDialog.Builder(main);
+ adb.setTitle(R.string.title_reflector_dialog);
+ Dialog d = adb.setView(dialogView)
+ .setCancelable(true)
+ .setPositiveButton(R.string.dialog_positive, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ int[] plugs = new int[26];
+ for (int i = 0; i < 26; i++) {
+ plugs[i] = buttons.get(i).getConnectedButton();
+ }
+ state.setConfigurationReflector(plugs);
+ main.onDialogFinished(state);
+ Toast.makeText(main.getApplication(), R.string.dialog_reflector_set, Toast.LENGTH_SHORT).show();
+ }
+ })
+ .setNegativeButton(R.string.dialog_negative, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ Toast.makeText(main, R.string.dialog_abort,
+ Toast.LENGTH_SHORT).show();
+ }
+ }).create();
+
+ WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
+ lp.copyFrom(d.getWindow().getAttributes());
+ lp.width = WindowManager.LayoutParams.MATCH_PARENT;
+ lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
+ d.show();
+ positive = ((AlertDialog)d).getButton(AlertDialog.BUTTON_POSITIVE);
+ if(!allConnectionsDone())
+ {
+ positive.setEnabled(false);
+ }
+ d.getWindow().setAttributes(lp);
+ }
+
+ /**
+ * Initialize array of buttons, initialize background-color hashset.
+ */
+ private void initializeLayout()
+ {
+ buttons = new ArrayList<>();
+ dialogView = View.inflate(main, R.layout.dialog_plugs, null);
+
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.A),0));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.B),1));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.C),2));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.D),3));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.E),4));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.F),5));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.G),6));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.H),7));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.I),8));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.J),9));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.K),10));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.L),11));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.M),12));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.N),13));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.O),14));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.P),15));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.Q),16));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.R),17));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.S),18));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.T),19));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.U),20));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.V),21));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.W),22));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.X),23));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.Y),24));
+ buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.Z),25));
+
+ colors = new HashSet<>();
+ colors.add(R.drawable.button_orange);
+ colors.add(R.drawable.button_olive);
+ colors.add(R.drawable.button_blue);
+ colors.add(R.drawable.button_red);
+ colors.add(R.drawable.button_yellow);
+ colors.add(R.drawable.button_purple);
+ colors.add(R.drawable.button_green);
+ colors.add(R.drawable.button_cyan);
+ colors.add(R.drawable.button_berry);
+ colors.add(R.drawable.button_brown);
+ colors.add(R.drawable.button_pink);
+ colors.add(R.drawable.button_elder);
+ colors.add(R.drawable.button_black);
+ }
+
+ /**
+ * Set listeners for all buttons
+ */
+ private void setButtonListeners()
+ {
+ for(int i=0; i<26; i++)
+ {
+ Button b = buttons.get(i).getButton();
+ final int id = i;
+ b.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ buttonPressed(id);
+ }
+ });
+ }
+ }
+
+ /**
+ * Check, whether all connections are done. If so, return true.
+ * return false otherwise
+ * @return boolean
+ */
+ private boolean allConnectionsDone()
+ {
+ for(int i=0; i it = colors.iterator();
+ res = it.next();
+ if(res == 0) res = it.next();
+ colors.remove(res);
+
+ b1.setResourceID(res);
+ b2.setResourceID(res);
+ }
+ updatePositiveButton();
+ }
+
+ /**
+ * Update state of positive button. Check, if all connections are done and if so, enable positive
+ * button. Otherwise disable it.
+ */
+ private void updatePositiveButton()
+ {
+ if(!allowIncompleteConnections && positive != null)
+ {
+ if(allConnectionsDone()) positive.setEnabled(true);
+ else positive.setEnabled(false);
+ }
+ }
+
+ /**
+ * Set buttons to not connected. That includes changing background to grey, set connection to
+ * itself.
+ * @param b index of button
+ */
+ private void setButtonFree(int b)
+ {
+ ButtonWrapper button = buttons.get(b);
+ int res = button.getResourceID();
+ if(res != R.drawable.button_grey)
+ colors.add(button.getResourceID());
+ button.setResourceID(R.drawable.button_grey);
+ button.setConnectedButton(b);
+ }
+
+ /**
+ * Handle button pressed events.
+ * @param button button that got pressed
+ */
+ private void buttonPressed(int button)
+ {
+ if(previouslyPressedButton != -1)
+ {
+ setPlug(previouslyPressedButton, button);
+ previouslyPressedButton = -1;
+ }
+ else
+ {
+ previouslyPressedButton = button;
+ buttons.get(button).setWaiting();
+ }
+ }
+
+ /**
+ * Wrapper class for Buttons, that also stores the index of both, the connected button, as well
+ * as the button itself and resourceID of used material.
+ */
+ private static class ButtonWrapper
+ {
+ private Button button;
+ private int connectedButton;
+ private int resourceID;
+ private int index;
+
+ /**
+ * Create ButtonWrapper
+ * @param button underlying Button
+ * @param index index of the button in the buttons array
+ */
+ public ButtonWrapper(Button button, int index)
+ {
+ this.button = button;
+ this.index = index;
+ this.connectedButton = index;
+ }
+
+ /**
+ * set the index of the connected button and update buttons text
+ * @param other index
+ */
+ public void setConnectedButton(int other)
+ {
+ this.connectedButton = other;
+ Resources res = MainActivity.ActivitySingleton.getInstance().getActivity().getResources();
+ this.getButton().setText(String.format(
+ res.getText(R.string.button_plug_title).toString(),
+ ""+(char) (index+65),
+ ""+(char) (connectedButton+65)));
+ }
+
+ /**
+ * return index of the connected button
+ * @return index of connected button
+ */
+ public int getConnectedButton()
+ {
+ return this.connectedButton;
+ }
+
+ /**
+ * Indicate, that this button is waiting for another button to connect to.
+ */
+ public void setWaiting()
+ {
+ Resources res = MainActivity.ActivitySingleton.getInstance().getActivity().getResources();
+ this.getButton().setText(String.format(
+ res.getText(R.string.button_plug_title).toString(),
+ ""+(char) (index+65)," "));
+ }
+
+ /**
+ * Set buttons background and store value in resourceID
+ * @param r resourceID of background material
+ */
+ public void setResourceID(int r)
+ {
+ button.setBackgroundResource(r);
+ this.resourceID = r;
+ }
+
+ /**
+ * get resourceID of buttons background as store in resourceID
+ * @return resourceID
+ */
+ public int getResourceID()
+ {
+ return this.resourceID;
+ }
+
+ /**
+ * Return stored button object
+ * @return button
+ */
+ public Button getButton()
+ {
+ return button;
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/RingSettingsDialogBuilder.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/RingSettingsDialogBuilder.java
new file mode 100644
index 0000000..9723e38
--- /dev/null
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/RingSettingsDialogBuilder.java
@@ -0,0 +1,405 @@
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.vanitasvitae.enigmandroid.layout;
+
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.util.Log;
+import android.view.View;
+import android.widget.ArrayAdapter;
+import android.widget.Spinner;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import de.vanitasvitae.enigmandroid.MainActivity;
+import de.vanitasvitae.enigmandroid.R;
+import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
+
+/**
+ * Builder for the dialog that is used to get settings for the rings
+ * Copyright (C) 2015 Paul Schaub
+ */
+public abstract class RingSettingsDialogBuilder
+{
+ protected abstract void showDialog(EnigmaStateBundle stateBundle, ArrayAdapter[] adapters, int[] rIDs, Actions actions);
+ public abstract void createRingSettingsDialog(EnigmaStateBundle stateBundle);
+
+ private static ArrayAdapter createAdapter(Integer[] array)
+ {
+ ArrayAdapter adapter = new ArrayAdapter<>(
+ MainActivity.ActivitySingleton.getInstance().getActivity(),
+ android.R.layout.simple_spinner_item, array);
+ adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ return adapter;
+ }
+
+ /**
+ * Creates a ArrayAdapter working over an array of numbers 1 to 26.
+ * @return ArrayAdapter
+ */
+ private static ArrayAdapter createAdapter1_26()
+ {
+ Integer[] ringArray = new Integer[26];
+ for(int i=1; i<=26; i++) {ringArray[i-1] = i;}
+ return createAdapter(ringArray);
+ }
+
+
+ /**
+ * DialogBuilder for 3 Spinners and ringSettingRotor1-3
+ */
+ public static class RingSettingsDialogBuilderRotRotRot extends RingSettingsDialogBuilder
+ {
+ public void createRingSettingsDialog(final EnigmaStateBundle state)
+ {
+ this.showDialog(state,
+ new ArrayAdapter[]{
+ createAdapter1_26(),
+ createAdapter1_26(),
+ createAdapter1_26()},
+ new int[]{
+ R.string.hint_rotor1,
+ R.string.hint_rotor2,
+ R.string.hint_rotor3},
+ new Actions3(state) {
+ @Override
+ protected void firstSpinnerItemSelected(int pos) {
+ state.setRingSettingRotor1(pos);
+ }
+
+ @Override
+ protected void secondSpinnerItemSelected(int pos) {
+ state.setRingSettingRotor2(pos);
+ }
+
+ @Override
+ protected void thirdSpinnerItemSelected(int pos) {
+ state.setRingSettingRotor3(pos);
+ }
+
+ @Override
+ protected int getFirstValueFromBundle() {
+ return state.getRingSettingRotor1();
+ }
+
+ @Override
+ protected int getSecondValueFromBundle() {
+ return state.getRingSettingRotor2();
+ }
+
+ @Override
+ protected int getThirdValueFromBundle() {
+ return state.getRingSettingRotor3();
+ }
+ });
+ }
+
+ @Override
+ protected void showDialog(final EnigmaStateBundle stateBundle, ArrayAdapter[] adapters, int[] rIDs, Actions actions)
+ {
+ if(adapters.length != 3 || rIDs.length != 3)
+ {
+ Log.e(MainActivity.APP_ID, "RingSettingsDialogBuilderRotRotRot.showDialog():" +
+ " Length of adapters array or length of rIDs array not equal to 3!");
+ }
+ final Actions3 action = (Actions3) actions;
+ final MainActivity main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity();
+ View ringSettingsView = View.inflate(main, R.layout.dialog_ringsettings_3, null);
+
+ TextView ring1Title = (TextView) ringSettingsView.findViewById(R.id.dialog_text_rotor1);
+ ring1Title.setText(rIDs[0]);
+ TextView ring2Title = (TextView) ringSettingsView.findViewById(R.id.dialog_text_rotor2);
+ ring2Title.setText(rIDs[1]);
+ TextView ring3Title = (TextView) ringSettingsView.findViewById(R.id.dialog_text_rotor3);
+ ring3Title.setText(rIDs[2]);
+
+ final Spinner ring1 = (Spinner) ringSettingsView.findViewById(R.id.rotor1ring);
+ ring1.setAdapter(adapters[0]);
+ ring1.setSelection(action.getFirstValueFromBundle());
+
+ final Spinner ring2 = (Spinner) ringSettingsView.findViewById(R.id.rotor2ring);
+ ring2.setAdapter(adapters[1]);
+ ring2.setSelection(action.getSecondValueFromBundle());
+
+ final Spinner ring3 = (Spinner) ringSettingsView.findViewById(R.id.rotor3ring);
+ ring3.setAdapter(adapters[2]);
+ ring3.setSelection(action.getThirdValueFromBundle());
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(main);
+ builder.setTitle(R.string.title_ring_setting);
+ builder.setView(ringSettingsView)
+ .setCancelable(true)
+ .setPositiveButton(R.string.dialog_positive, new DialogInterface.OnClickListener()
+ {
+ public void onClick(DialogInterface dialog, int id)
+ {
+ action.firstSpinnerItemSelected(ring1.getSelectedItemPosition());
+ action.secondSpinnerItemSelected(ring2.getSelectedItemPosition());
+ action.thirdSpinnerItemSelected(ring3.getSelectedItemPosition());
+ String message = String.format(main.getResources().getString(
+ R.string.dialog_ring_settings_success),
+ (ring1.getSelectedItemPosition()+1) + ", " +
+ (ring2.getSelectedItemPosition()+1) + ", " +
+ (ring3.getSelectedItemPosition()+1));
+ main.onDialogFinished(stateBundle);
+ Toast.makeText(main, message, Toast.LENGTH_LONG).show();
+ }
+ })
+ .setNegativeButton(R.string.dialog_negative, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ Toast.makeText(main, R.string.dialog_abort,
+ Toast.LENGTH_SHORT).show();
+ }
+ }).show();
+ }
+ }
+
+ /**
+ * DialogBuilder for 4 Spinners and ringSettingRotor1-3, ringSettingReflector
+ */
+ public static class RingSettingsDialogBuilderRotRotRotRef extends RingSettingsDialogBuilder
+ {
+ @Override
+ public void createRingSettingsDialog(final EnigmaStateBundle state) {
+ this.showDialog(state,
+ new ArrayAdapter[]{
+ createAdapter1_26(),
+ createAdapter1_26(),
+ createAdapter1_26(),
+ createAdapter1_26()},
+ new int[]{
+ R.string.hint_rotor1,
+ R.string.hint_rotor2,
+ R.string.hint_rotor3,
+ R.string.hint_reflector},
+ new Actions4(state) {
+
+ @Override
+ protected void firstSpinnerItemSelected(int pos) {
+ state.setRingSettingRotor1(pos);
+ }
+
+ @Override
+ protected void secondSpinnerItemSelected(int pos) {
+ state.setRingSettingRotor2(pos);
+ }
+
+ @Override
+ protected void thirdSpinnerItemSelected(int pos) {
+ state.setRingSettingRotor3(pos);
+ }
+
+ @Override
+ protected int getFirstValueFromBundle() {
+ return state.getRingSettingRotor1();
+ }
+
+ @Override
+ protected int getSecondValueFromBundle() {
+ return state.getRingSettingRotor2();
+ }
+
+ @Override
+ protected int getThirdValueFromBundle() {
+ return state.getRingSettingRotor3();
+ }
+
+ @Override
+ protected void fourthSpinnerItemSelected(int pos) {
+ state.setRingSettingReflector(pos);
+ }
+
+ @Override
+ protected int getFourthValueFromBundle() {
+ return state.getRingSettingReflector();
+ }
+ });
+ }
+ @Override
+ protected void showDialog(final EnigmaStateBundle stateBundle, ArrayAdapter[] adapters, int[] rIDs, Actions actions) {
+ if(adapters.length != 4 || rIDs.length != 4)
+ {
+ Log.d(MainActivity.APP_ID, "RingSettingsDialogBuilderRotRotRotRef.showDialog():" +
+ "Length of adapters array or length of rIDs array not equal to 4!");
+ }
+ final Actions4 action = (Actions4) actions;
+ final MainActivity main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity();
+ View ringSettingsView = View.inflate(main, R.layout.dialog_ringsettings_4, null);
+
+ TextView ring1Title = (TextView) ringSettingsView.findViewById(R.id.dialog_text_rotor1);
+ ring1Title.setText(rIDs[0]);
+ TextView ring2Title = (TextView) ringSettingsView.findViewById(R.id.dialog_text_rotor2);
+ ring2Title.setText(rIDs[1]);
+ TextView ring3Title = (TextView) ringSettingsView.findViewById(R.id.dialog_text_rotor3);
+ ring3Title.setText(rIDs[2]);
+ TextView ring4Title = (TextView) ringSettingsView.findViewById(R.id.dialog_text_rotor4);
+ ring4Title.setText(rIDs[3]);
+
+ final Spinner ring1 = (Spinner) ringSettingsView.findViewById(R.id.rotor1ring);
+ ring1.setAdapter(adapters[0]);
+ ring1.setSelection(action.getFirstValueFromBundle());
+
+ final Spinner ring2 = (Spinner) ringSettingsView.findViewById(R.id.rotor2ring);
+ ring2.setAdapter(adapters[1]);
+ ring2.setSelection(action.getSecondValueFromBundle());
+
+ final Spinner ring3 = (Spinner) ringSettingsView.findViewById(R.id.rotor3ring);
+ ring3.setAdapter(adapters[2]);
+ ring3.setSelection(action.getThirdValueFromBundle());
+
+ final Spinner ring4 = (Spinner) ringSettingsView.findViewById(R.id.rotor4ring);
+ ring4.setAdapter(adapters[3]);
+ ring4.setSelection(action.getFourthValueFromBundle());
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(main);
+ builder.setTitle(R.string.title_ring_setting);
+ builder.setView(ringSettingsView)
+ .setCancelable(true)
+ .setPositiveButton(R.string.dialog_positive, new DialogInterface.OnClickListener()
+ {
+ public void onClick(DialogInterface dialog, int id)
+ {
+ action.firstSpinnerItemSelected(ring1.getSelectedItemPosition());
+ action.secondSpinnerItemSelected(ring2.getSelectedItemPosition());
+ action.thirdSpinnerItemSelected(ring3.getSelectedItemPosition());
+ action.fourthSpinnerItemSelected(ring4.getSelectedItemPosition());
+ String message = String.format(main.getResources().getString(
+ R.string.dialog_ring_settings_success),
+ (ring1.getSelectedItemPosition()+1) + ", " +
+ (ring2.getSelectedItemPosition()+1) + ", " +
+ (ring3.getSelectedItemPosition()+1) + ", " +
+ (ring4.getSelectedItemPosition()+1));
+ main.onDialogFinished(stateBundle);
+ Toast.makeText(main, message, Toast.LENGTH_LONG).show();
+ }
+ })
+ .setNegativeButton(R.string.dialog_negative, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ Toast.makeText(main, R.string.dialog_abort,
+ Toast.LENGTH_SHORT).show();
+ }
+ }).show();
+ }
+ }
+
+ /**
+ * DialogBuilder for 4 Spinners and ringSettingRotor1-4
+ */
+ public static class RingSettingsDialogBuilderRotRotRotRot extends RingSettingsDialogBuilderRotRotRotRef
+ {
+ @Override
+ public void createRingSettingsDialog(final EnigmaStateBundle state) {
+ this.showDialog(state,
+ new ArrayAdapter[]{
+ createAdapter1_26(),
+ createAdapter1_26(),
+ createAdapter1_26(),
+ createAdapter1_26()},
+ new int[]{
+ R.string.hint_rotor1,
+ R.string.hint_rotor2,
+ R.string.hint_rotor3,
+ R.string.hint_thin_rotor},
+ new Actions4(state) {
+
+ @Override
+ protected void firstSpinnerItemSelected(int pos) {
+ state.setRingSettingRotor1(pos);
+ }
+
+ @Override
+ protected void secondSpinnerItemSelected(int pos) {
+ state.setRingSettingRotor2(pos);
+ }
+
+ @Override
+ protected void thirdSpinnerItemSelected(int pos) {
+ state.setRingSettingRotor3(pos);
+ }
+
+ @Override
+ protected int getFirstValueFromBundle() {
+ return state.getRingSettingRotor1();
+ }
+
+ @Override
+ protected int getSecondValueFromBundle() {
+ return state.getRingSettingRotor2();
+ }
+
+ @Override
+ protected int getThirdValueFromBundle() {
+ return state.getRingSettingRotor3();
+ }
+
+ @Override
+ protected void fourthSpinnerItemSelected(int pos) {
+ state.setRingSettingRotor4(pos);
+ }
+
+ @Override
+ protected int getFourthValueFromBundle() {
+ return state.getRingSettingRotor4();
+ }
+ });
+ }
+ }
+
+ /**
+ * Abstract class that defines how Spinners correspond to the EnigmaStateBundle
+ */
+ public static abstract class Actions
+ {
+ final EnigmaStateBundle stateBundle;
+ public Actions(EnigmaStateBundle bundle)
+ {
+ this.stateBundle = bundle;
+ }
+ }
+
+ /**
+ * Abstract class that defines, how the 3 Spinners correspond to 3 values in the
+ * EnigmaStateBundle
+ */
+ public static abstract class Actions3 extends Actions
+ {
+ public Actions3(EnigmaStateBundle bundle)
+ {
+ super(bundle);
+ }
+ protected abstract void firstSpinnerItemSelected(int pos);
+ protected abstract void secondSpinnerItemSelected(int pos);
+ protected abstract void thirdSpinnerItemSelected(int pos);
+ protected abstract int getFirstValueFromBundle();
+ protected abstract int getSecondValueFromBundle();
+ protected abstract int getThirdValueFromBundle();
+ }
+
+ /**
+ * Extension of Actions3 which forces implementing classes to implement methods for the fourth
+ * Spinner.
+ */
+ public static abstract class Actions4 extends Actions3
+ {
+ public Actions4(EnigmaStateBundle bundle)
+ {
+ super(bundle);
+ }
+ protected abstract void fourthSpinnerItemSelected(int pos);
+ protected abstract int getFourthValueFromBundle();
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/drawable-hdpi/ic_launcher.png b/app/src/main/res/drawable-hdpi/ic_launcher.png
index 9e6a7e8..6920ac5 100644
Binary files a/app/src/main/res/drawable-hdpi/ic_launcher.png and b/app/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/app/src/main/res/drawable-hdpi/ic_send_white_48dp.png b/app/src/main/res/drawable-hdpi/ic_send_white_48dp.png
new file mode 100644
index 0000000..1bc7552
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_send_white_48dp.png differ
diff --git a/app/src/main/res/drawable-ldrtl-hdpi/ic_send_white_48dp.png b/app/src/main/res/drawable-ldrtl-hdpi/ic_send_white_48dp.png
new file mode 100644
index 0000000..9f64e5b
Binary files /dev/null and b/app/src/main/res/drawable-ldrtl-hdpi/ic_send_white_48dp.png differ
diff --git a/app/src/main/res/drawable-ldrtl-mdpi/ic_send_white_48dp.png b/app/src/main/res/drawable-ldrtl-mdpi/ic_send_white_48dp.png
new file mode 100644
index 0000000..4735a7d
Binary files /dev/null and b/app/src/main/res/drawable-ldrtl-mdpi/ic_send_white_48dp.png differ
diff --git a/app/src/main/res/drawable-ldrtl-xhdpi/ic_send_white_48dp.png b/app/src/main/res/drawable-ldrtl-xhdpi/ic_send_white_48dp.png
new file mode 100644
index 0000000..76d135b
Binary files /dev/null and b/app/src/main/res/drawable-ldrtl-xhdpi/ic_send_white_48dp.png differ
diff --git a/app/src/main/res/drawable-ldrtl-xxhdpi/ic_send_white_48dp.png b/app/src/main/res/drawable-ldrtl-xxhdpi/ic_send_white_48dp.png
new file mode 100644
index 0000000..a16ec5c
Binary files /dev/null and b/app/src/main/res/drawable-ldrtl-xxhdpi/ic_send_white_48dp.png differ
diff --git a/app/src/main/res/drawable-ldrtl-xxxhdpi/ic_send_white_48dp.png b/app/src/main/res/drawable-ldrtl-xxxhdpi/ic_send_white_48dp.png
new file mode 100644
index 0000000..e949db7
Binary files /dev/null and b/app/src/main/res/drawable-ldrtl-xxxhdpi/ic_send_white_48dp.png differ
diff --git a/app/src/main/res/drawable-mdpi/ic_launcher.png b/app/src/main/res/drawable-mdpi/ic_launcher.png
index 4ec831a..fe216c6 100644
Binary files a/app/src/main/res/drawable-mdpi/ic_launcher.png and b/app/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/app/src/main/res/drawable-mdpi/ic_send_white_48dp.png b/app/src/main/res/drawable-mdpi/ic_send_white_48dp.png
new file mode 100644
index 0000000..ef59e77
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_send_white_48dp.png differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_launcher.png b/app/src/main/res/drawable-xhdpi/ic_launcher.png
index c5d10eb..33303b3 100644
Binary files a/app/src/main/res/drawable-xhdpi/ic_launcher.png and b/app/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_send_white_48dp.png b/app/src/main/res/drawable-xhdpi/ic_send_white_48dp.png
new file mode 100644
index 0000000..6aeaa85
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_send_white_48dp.png differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/app/src/main/res/drawable-xxhdpi/ic_launcher.png
index 9954998..532387a 100644
Binary files a/app/src/main/res/drawable-xxhdpi/ic_launcher.png and b/app/src/main/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_send_white_48dp.png b/app/src/main/res/drawable-xxhdpi/ic_send_white_48dp.png
new file mode 100644
index 0000000..14b90dd
Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_send_white_48dp.png differ
diff --git a/app/src/main/res/drawable-xxxhdpi/ic_launcher.png b/app/src/main/res/drawable-xxxhdpi/ic_launcher.png
new file mode 100644
index 0000000..b3d98b6
Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/drawable-xxxhdpi/ic_send_white_48dp.png b/app/src/main/res/drawable-xxxhdpi/ic_send_white_48dp.png
new file mode 100644
index 0000000..30f8b26
Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_send_white_48dp.png differ
diff --git a/app/src/main/res/drawable/button_berry.xml b/app/src/main/res/drawable/button_berry.xml
new file mode 100644
index 0000000..94ca28f
--- /dev/null
+++ b/app/src/main/res/drawable/button_berry.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/button_black.xml b/app/src/main/res/drawable/button_black.xml
new file mode 100644
index 0000000..535cbac
--- /dev/null
+++ b/app/src/main/res/drawable/button_black.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/button_blue.xml b/app/src/main/res/drawable/button_blue.xml
new file mode 100644
index 0000000..a60076b
--- /dev/null
+++ b/app/src/main/res/drawable/button_blue.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/button_brown.xml b/app/src/main/res/drawable/button_brown.xml
new file mode 100644
index 0000000..b8d820f
--- /dev/null
+++ b/app/src/main/res/drawable/button_brown.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/button_cyan.xml b/app/src/main/res/drawable/button_cyan.xml
new file mode 100644
index 0000000..a3001bd
--- /dev/null
+++ b/app/src/main/res/drawable/button_cyan.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/button_elder.xml b/app/src/main/res/drawable/button_elder.xml
new file mode 100644
index 0000000..cab7d35
--- /dev/null
+++ b/app/src/main/res/drawable/button_elder.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/button_green.xml b/app/src/main/res/drawable/button_green.xml
new file mode 100644
index 0000000..c399bbf
--- /dev/null
+++ b/app/src/main/res/drawable/button_green.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/button_grey.xml b/app/src/main/res/drawable/button_grey.xml
new file mode 100644
index 0000000..0e415cc
--- /dev/null
+++ b/app/src/main/res/drawable/button_grey.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/button_olive.xml b/app/src/main/res/drawable/button_olive.xml
new file mode 100644
index 0000000..be9653f
--- /dev/null
+++ b/app/src/main/res/drawable/button_olive.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/button.xml b/app/src/main/res/drawable/button_orange.xml
similarity index 100%
rename from app/src/main/res/drawable/button.xml
rename to app/src/main/res/drawable/button_orange.xml
diff --git a/app/src/main/res/drawable/button_pink.xml b/app/src/main/res/drawable/button_pink.xml
new file mode 100644
index 0000000..1c5aa9e
--- /dev/null
+++ b/app/src/main/res/drawable/button_pink.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/button_purple.xml b/app/src/main/res/drawable/button_purple.xml
new file mode 100644
index 0000000..216d39f
--- /dev/null
+++ b/app/src/main/res/drawable/button_purple.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/button_red.xml b/app/src/main/res/drawable/button_red.xml
new file mode 100644
index 0000000..6f34d28
--- /dev/null
+++ b/app/src/main/res/drawable/button_red.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/button_yellow.xml b/app/src/main/res/drawable/button_yellow.xml
new file mode 100644
index 0000000..c29d0f4
--- /dev/null
+++ b/app/src/main/res/drawable/button_yellow.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/ic_launcher-web.png b/app/src/main/res/ic_launcher-web.png
index ca36cd3..9edf183 100644
Binary files a/app/src/main/res/ic_launcher-web.png and b/app/src/main/res/ic_launcher-web.png differ
diff --git a/app/src/main/res/icon.svg b/app/src/main/res/icon.svg
new file mode 100644
index 0000000..ef9d2ad
--- /dev/null
+++ b/app/src/main/res/icon.svg
@@ -0,0 +1,653 @@
+
+
+
+
diff --git a/app/src/main/res/layout-land/activity_main_d.xml b/app/src/main/res/layout-land/activity_main_d.xml
new file mode 100644
index 0000000..27e8f09
--- /dev/null
+++ b/app/src/main/res/layout-land/activity_main_d.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout-land/activity_main_g_k_r_t.xml b/app/src/main/res/layout-land/activity_main_g_k_r_t.xml
new file mode 100644
index 0000000..540e494
--- /dev/null
+++ b/app/src/main/res/layout-land/activity_main_g_k_r_t.xml
@@ -0,0 +1,144 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout-land/activity_main.xml b/app/src/main/res/layout-land/activity_main_i_m3.xml
similarity index 90%
rename from app/src/main/res/layout-land/activity_main.xml
rename to app/src/main/res/layout-land/activity_main_i_m3.xml
index 999fa12..ae0e078 100644
--- a/app/src/main/res/layout-land/activity_main.xml
+++ b/app/src/main/res/layout-land/activity_main_i_m3.xml
@@ -119,41 +119,13 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout-land/activity_main_m4.xml b/app/src/main/res/layout-land/activity_main_m4.xml
new file mode 100644
index 0000000..cc10fa9
--- /dev/null
+++ b/app/src/main/res/layout-land/activity_main_m4.xml
@@ -0,0 +1,201 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout-land/dialog_plugs.xml b/app/src/main/res/layout-land/dialog_plugs.xml
new file mode 100644
index 0000000..9afcbc3
--- /dev/null
+++ b/app/src/main/res/layout-land/dialog_plugs.xml
@@ -0,0 +1,254 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout-v14/dialog_about.xml b/app/src/main/res/layout-v14/dialog_about.xml
new file mode 100644
index 0000000..b32a466
--- /dev/null
+++ b/app/src/main/res/layout-v14/dialog_about.xml
@@ -0,0 +1,88 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_main_d.xml b/app/src/main/res/layout/activity_main_d.xml
new file mode 100644
index 0000000..c4435f3
--- /dev/null
+++ b/app/src/main/res/layout/activity_main_d.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_main_g_k_r_t.xml b/app/src/main/res/layout/activity_main_g_k_r_t.xml
new file mode 100644
index 0000000..f433686
--- /dev/null
+++ b/app/src/main/res/layout/activity_main_g_k_r_t.xml
@@ -0,0 +1,162 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main_i_m3.xml
similarity index 87%
rename from app/src/main/res/layout/activity_main.xml
rename to app/src/main/res/layout/activity_main_i_m3.xml
index 4d66f99..1b6e717 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main_i_m3.xml
@@ -78,7 +78,7 @@
android:layout_below="@+id/lin_lay_1"
android:id="@+id/lin_lay_names_2">
-
@@ -99,7 +99,7 @@
android:layout_weight=".25"
android:layout_height="wrap_content"
android:text="@string/hint_rotor1_position"/>
-
@@ -112,7 +112,7 @@
android:id="@+id/lin_lay_2"
android:layout_below="@+id/lin_lay_names_2">
-
@@ -134,23 +134,16 @@
android:layout_height="wrap_content"
android:id="@+id/rotor1position">
-
-
-
@@ -176,14 +170,22 @@
android:id="@+id/buttons_lay"
android:layout_alignParentBottom="true">
+
+ android:background="@drawable/button_orange"
+ tools:ignore="ButtonStyle"/>
diff --git a/app/src/main/res/layout/activity_main_kd.xml b/app/src/main/res/layout/activity_main_kd.xml
new file mode 100644
index 0000000..8359358
--- /dev/null
+++ b/app/src/main/res/layout/activity_main_kd.xml
@@ -0,0 +1,171 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_main_m4.xml b/app/src/main/res/layout/activity_main_m4.xml
new file mode 100644
index 0000000..07936e5
--- /dev/null
+++ b/app/src/main/res/layout/activity_main_m4.xml
@@ -0,0 +1,198 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/dialog_about.xml b/app/src/main/res/layout/dialog_about.xml
index 84cdf9e..aa9a42d 100644
--- a/app/src/main/res/layout/dialog_about.xml
+++ b/app/src/main/res/layout/dialog_about.xml
@@ -1,11 +1,9 @@
-
-
-
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:paddingStart="5dp"
+ android:paddingEnd="5dp">
@@ -31,29 +29,28 @@
@@ -61,14 +58,14 @@
@@ -76,18 +73,16 @@
-
-
-
+
diff --git a/app/src/main/res/layout/dialog_passphrase.xml b/app/src/main/res/layout/dialog_passphrase.xml
new file mode 100644
index 0000000..c560ed0
--- /dev/null
+++ b/app/src/main/res/layout/dialog_passphrase.xml
@@ -0,0 +1,12 @@
+
+
+
diff --git a/app/src/main/res/layout/dialog_plugs.xml b/app/src/main/res/layout/dialog_plugs.xml
new file mode 100644
index 0000000..277468f
--- /dev/null
+++ b/app/src/main/res/layout/dialog_plugs.xml
@@ -0,0 +1,298 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/dialog_ringsettings.xml b/app/src/main/res/layout/dialog_ringsettings_3.xml
similarity index 81%
rename from app/src/main/res/layout/dialog_ringsettings.xml
rename to app/src/main/res/layout/dialog_ringsettings_3.xml
index b051e3d..5040b16 100644
--- a/app/src/main/res/layout/dialog_ringsettings.xml
+++ b/app/src/main/res/layout/dialog_ringsettings_3.xml
@@ -1,7 +1,9 @@
+ android:layout_height="wrap_content"
+ android:paddingStart="5dp"
+ android:paddingEnd="5dp">
@@ -35,19 +37,19 @@
diff --git a/app/src/main/res/layout/dialog_ringsettings_4.xml b/app/src/main/res/layout/dialog_ringsettings_4.xml
new file mode 100644
index 0000000..73110ee
--- /dev/null
+++ b/app/src/main/res/layout/dialog_ringsettings_4.xml
@@ -0,0 +1,70 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/dialog_two_options.xml b/app/src/main/res/layout/dialog_two_options.xml
new file mode 100644
index 0000000..2ae79f1
--- /dev/null
+++ b/app/src/main/res/layout/dialog_two_options.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/dialog_whats_new.xml b/app/src/main/res/layout/dialog_whats_new.xml
new file mode 100644
index 0000000..b33ba1a
--- /dev/null
+++ b/app/src/main/res/layout/dialog_whats_new.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml
index a8e82ee..eb29514 100644
--- a/app/src/main/res/menu/main.xml
+++ b/app/src/main/res/menu/main.xml
@@ -1,21 +1,55 @@
diff --git a/app/src/main/res/render-icon.sh b/app/src/main/res/render-icon.sh
new file mode 100644
index 0000000..156efea
--- /dev/null
+++ b/app/src/main/res/render-icon.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+# Converts the Inkscape icon file ic_launcher_web.svg to the launcher web & app png files.
+
+PROJECT="/home/vanitas/Programmierung/androidstudio/EnigmAndroid/app"
+MAIN="${PROJECT}/src/main/"
+RES="${MAIN}res/"
+DRAWABLE="${RES}drawable"
+INPUT="${RES}icon.svg"
+
+inkscape --shell <EnigmAndroid ist die Implementation einer Simulation der Enigma Maschine.
Die Enigma Maschine ist eine in den 1920er Jahren entwickelte Verschlüsselungsmaschine,
die unter anderem im zweiten Weltkrieg von der deutschen Wehrmacht eingesetzt wurde,
- um geheime Nachrichten zu verschlüsseln. Dabei wird jeder einzelne Buchstabe elektronisch
+ um geheime Nachrichten zu verschlüsseln. Es gab mehrere verschiedene Enigmamodelle.
+ Zur Verschlüsselung wird jeder einzelne Buchstabe elektronisch
durch eine Reihe von rotierbaren Walzen geleitet, sodass nach jedem Buchstaben ein anderes
Verschlüsselungsalphabet genutzt wird (Polyalphabetische Substitution).
Die Walzen konnte man aus einem Set von 5 Walzen wählen. Zusätzlich gab es ein Steckbrett, an dem
@@ -16,12 +17,18 @@
Bedienungsanleitung
- Um einen Text mit EnigmAndroid zu ver- oder entschlüsseln, tippen Sie den Klar- oder Geheimtext in das Feld \"Hier tippen\".
- Wählen Sie anschließend eine Umkehrwalze, und Walzen für die Plätze 1 bis 3 aus. Legen Sie außerdem die Startpositionen der Walzen fest.
- Zuletzt können Sie noch einige Steckerpaare auf dem Steckbrett festlegen. Tippen Sie dazu die gewünschten Paare mit Komma getrennt in das entsprechende Textfeld (zb. \"ab,cd\").
- Beachten Sie, dass Sie einen Stecker nicht doppelt nutzen dürfen.
- Optional können Sie auch noch die Ringstellung definieren. Öffnen Sie dazu das Optionsmenü und wählen Sie den Punkt \"Ringstellung\".
- Haben Sie alle Einstellungen getätigt klicken Sie auf den Button \"Ver-Entschlüsseln\".
+ Um einen Text mit EnigmAndroid zu ver- oder entschlüsseln, wählen Sie zunächst das entsprechende Maschinenmodell aus.
+ Sie finden eine Liste, aus der Sie wählen können in den Einstellungen. Tippen Sie dann den Klar- oder Geheimtext in das Feld \"Hier tippen\".
+ Wählen Sie anschließend je nach gewähltem Modell eine Umkehrwalze, sowie weitere Walzen aus. Legen Sie außerdem die Startpositionen der Walzen fest.
+ Zuletzt können Sie ggf. noch einige Steckerpaare auf dem Steckbrett festlegen, oder die Verkabelung der Umkehrwalze ändern. Tippen Sie dazu den
+ jeweiligen Button an und verbinden Sie die gewünschten Steckerpaare, indem Sie im sich öffnenden Dialog nacheinander jeweils zwei
+ Stecker berühren. Falls sie eine Verbindung trennen möchten, klicken Sie einen der betroffenen Stecker doppelt an.
+ Optional können Sie außerdem auch noch die Ringstellung definieren. Öffnen Sie dazu das Optionsmenü und wählen Sie den Punkt \"Ringstellung\".
+ Haben Sie alle Einstellungen getätigt klicken Sie auf den Button \"Ver-Entschlüsseln\".
+ Um die gewählte Konfiguration der Enigma Maschine per QR-Code zu teilen, wählen Sie den Eintrag \"Teile Konfiguration per QR-Code\" aus dem Optionsmenü.
+ Um eine per QR-Code geteilte Konfiguration zu scannen, wählen Sie stattdessen den Eintrag \"Lese Konfiguration aus QR-Code\".
+ Außerdem können Sie eine Konfiguration aus einem Schlüsselwort generieren, oder wiederherstellen, indem Sie dein Eintrag \"Konfiguration aus Schlüsselwort\"
+ wählen und im erscheinenden Dialog entweder ein beliebiges Wort oder den Inhalt eines QR-Codes (\"EnigmAndroid/…\" eingeben.EntwicklerEnigmAndroid wird entwickelt von: \nPaul Schaub
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index 8bd8f50..c2785e3 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -4,97 +4,51 @@
EnigmAndroidVersionZurücksetzen
+ Zufällige Konfiguration
+ Konfiguration wiederherstellen
+ Konfiguration teilenEinstellungen
- Ringstellung
- Wähle die Ringstellungen für die Walzen:
+ Ringstellung
+ Senden
+ Senden an…Hier TippenEnigma-Code
- Steckerbrett (AZ,BE...)Walze 1Walze 2Walze 3
+ Walze 4Umkehr-\nWalzePosition\nWalze 1Position\nWalze 2Position\nWalze 3
+ Position\nUmkehr-\nWalze
+ Position\nWalze 4
+ Verkabelung Umkehrwalze
+ Schlüsselwort/KonfigurationVer-/Entschlüsseln
- Fehler: Fehlerhafte Steckerbrettkonfiguration.
- Kann Stecker nicht setzen:
- Fehler: Einer oder mehrere dieser Stecker sind bereits in Benutzung:
- Ringstellungen
- OK
- Abbrechen
- Setze Ringe auf
- Keine Änderungen
- Enigma zurückgesetzt
+ Nachricht ist leer.
+ Fehler: Kein korrekter EnigmAndroid QR-Code!
+ Ringstellungen
-
- I
- II
- III
- IV
- V
-
-
- A
- B
- C
-
-
- A
- B
- C
- D
- E
- F
- G
- H
- I
- J
- K
- L
- M
- N
- O
- P
- Q
- R
- S
- T
- U
- V
- W
- X
- Y
- Z
-
+ Steckbrett-\nVerbindungen
+ Verkabelung Umkehrwalze
+
+ OK
+ Abbrechen
+ Konfiguration wiederherstellen…
+ …aus Text/Schlüsselwort
+ …aus QR-code
+ Konfiguration teilen…
+ …per QR-code
+ …als kodierten Text
+ Setze Ringe auf %1$s.
+ Umkehrwalze verkabelt.
+ Steckbrettverbindungen gesetzt.
+ Konfiguration aus Schlüsselwort %1$s generiert.
+ Konfiguration aus Kodierung wiederhergestellt.
+ Keine Änderungen.
+ Enigma zurückgesetzt.
+ Enigma auf zufällige Konfiguration gesetzt.
+ In Zwischenablage kopiert
-
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
-
diff --git a/app/src/main/res/values-de/strings_activity_settings.xml b/app/src/main/res/values-de/strings_activity_settings.xml
index 7b6d4b1..512839f 100644
--- a/app/src/main/res/values-de/strings_activity_settings.xml
+++ b/app/src/main/res/values-de/strings_activity_settings.xml
@@ -1,11 +1,43 @@
Einstellungen
-
-
Simulation
+ Enigma Modell
+ Welches Modell soll simuliert werden?
+
+ I (Heer, Luftwaffe)
+ M3 (Heer, Marine)
+ M4 (\"Shark\", Marine)
+ G31/A865 (Abwehr)
+ G312 (Abwehr)
+ G260 (Abwehr)
+ D (Kommerziell)
+ K
+ Swiss-K (Schweiz)
+ Swiss-K (Schweiz, Luftwaffe)
+ KD
+ R (\"Rocket\", Reichsbahn)
+ T (\"Tirpitz\", Japan)
+
- Doppelschritt Anomalie
- Die Doppelschritt Anomalie lässt die mittlere Walze zweimal rotieren, falls sie sich vor dem Übertragspunkt befindet.
-
+ Klartextvorbereitung
+ Zahlenbuchstabiersprache
+ Sprache in der Zahlen buchstabiert werden sollen.
+
+ Deutsch
+ Englisch
+ Französisch
+ Spanisch
+ Italienisch
+ Keine Ersetzung
+
+ Erscheinungsbild
+ Nachrichtenformatierung
+ Soll die Nachricht in Blöcke unterteilt werden?
+
+ Keine Unterteilung
+ Viererblöcke
+ Fünferblöcke
+ Sechserblöcke
+
diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml
new file mode 100644
index 0000000..ead0f3d
--- /dev/null
+++ b/app/src/main/res/values-pt-rBR/strings.xml
@@ -0,0 +1,51 @@
+
+
+ EnigmAndroid
+ Versão
+ Restaurar
+ Configuração aleatória
+ Restaurar configuração
+ Compartilhar configuração
+ Configurações de toque
+ Configurações
+ Enviar
+ Enviar para…
+ Escreva aqui
+ EnigmaCode
+ Rotor 1
+ Rotor 2
+ Rotor 3
+ Rotor 4
+ Refletor
+ Posição\nRotor 1
+ Posição\nRotor 2
+ Posição\nRotor 3
+ Posição\nRefletor
+ Posição\nRotor 4
+ Refletor de Fios
+ Senha/Configuração
+ En-/Decriptar!
+ Impossível enviar texto vazio.
+ Erro: Não é um QR-Code válido do EnigmAndroid!
+ Configurações de Toque
+ Configurações do Quadro de Conexões
+ Cabos do Refletor
+ OK
+ Cancelar
+ Restaurar configurações…
+ …a partir de texto
+ …a partir de QR-code
+ Compartilhar configurações…
+ …como QR-code
+ …criptografadas em texto
+ Definir as Configurações de Toque para %1$s.
+ Refletor Religado.
+ Definir configurações do Quadro de Conexões.
+ Gerar configurações a partir de senha %1$s.
+ Configurações restauradas do estado codificado.
+ Sem alterações.
+ Restaurar o Enigma.
+ Enigma definido para configurações aleatórias.
+ Copiado para a área de transferência
+
+
diff --git a/app/src/main/res/values-v11/styles.xml b/app/src/main/res/values-v11/styles.xml
new file mode 100644
index 0000000..bdbe3f2
--- /dev/null
+++ b/app/src/main/res/values-v11/styles.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/about_dialog_resources.xml b/app/src/main/res/values/about_dialog_resources.xml
index 4323fcc..ccde5fd 100644
--- a/app/src/main/res/values/about_dialog_resources.xml
+++ b/app/src/main/res/values/about_dialog_resources.xml
@@ -7,18 +7,22 @@
About EnigmAndroidEnigmAndroid is an implementation of a simulation of the Enigma Machine.
The Enigma Machine is a cypher machine developed in the 1920s. It was used by the german Wehrmacht to
- encipher secret messaged during the second world war. For enciphering text, every letter is passed through 3 mechanical rotors that rotate with every keypress.
+ encipher secret messaged during the second world war. There were multiple different Enigma models. For enciphering text, every letter is passed through 3-4 mechanical rotors that rotate with every keystroke.
That way the enigma achieves polyalphabetic substitution and the output appears random. The rotors could be chosen from a set of 5. Additionally there was a
so called plugboard, where one could switch over pairs of letters.
How to use
- To encrypt/decrpyt a message, you can type it into the input field.
- Afterwards you can select a reflector and the three rotors. Also select their initial positions.
- Then you can set pairs on the plugboard. Therefore you just type the pairs separated by commas (e.g. \"ab,cd\").
- Notice that you can\'t plug a letter twice.
- Optionally you can set custom ring settings. Open the options menu and select \"Ringsettings\".
- When you are ready press \"En-/Decrypt!\".
+ At first, choose a model of the enigma machine to work with.
+ You can do this in the settings. To encrypt/decrypt a message, you can name it into the input field.
+ Afterwards you can - depending on the chosen model - select a reflector and the some rotors. Also select their initial positions.
+ Then you may set pairs on the plugboard or on the pluggable reflector.
+ Therefore press the respective button and connect the characters you wish to connect by clicking them one after another.
+ If you want to disconnect two plugs, just touch one of the plugs twice.
+ Also you can optionally set custom ring settings. Open the options menu and select \"Ring-Settings\".
+ When you are ready press \"En-/Decrypt!\". To share the configuration of the enigma machine via QR-Code, just open the options
+ menu and select the entry \"Share configuration via QR-Code\". To scan a QR-Code, choose the respective entry.
+ Also you can enter a codeword or the content of a QR-Code by clicking on the entry \"Create configuration from passphrase\" to restore a configuration that way.DeveloperEnigmAndroid is developed by: \nPaul Schaub
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index a95d2ec..3fe3734 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,100 +1,89 @@
-
- 0.1.3-14.03.2015EnigmAndroidVersionReset
- Ringsettings
+ Random configuration
+ Restore configuration
+ Share configuration
+ Ring-SettingsSettings
- Choose ringsettings for the rotors:
+ Send
+ Send to…Type hereEnigmaCode
- Plugboard (AZ,BE...)Rotor 1Rotor 2Rotor 3
+ Rotor 4Reflector
- Position Rotor 1
- Position Rotor 2
- Position Rotor 3
+ Position\nRotor 1
+ Position\nRotor 2
+ Position\nRotor 3
+ Position\nReflector
+ Position\nRotor 4
+ Wiring Reflector
+ Passphrase/ConfigurationEn-/Decrypt!
- Error: Can\'t interpret Plugboard Input.
- Unable to plug
- Error: One or more of these Plugs are already in use:
- Ringsettings
- OK
- Cancel
- Set Ringsettings to
- No changes
- Enigma reset
+ Can\'t send empty text.
+ Error: Not a valid EnigmAndroid QR-Code!
+ Ring-Settings
+ Plugboard Settings
+ Reflector Wiring
+ OK
+ Cancel
+ Restore configuration…
+ …from text
+ …from QR-code
+ Share configuration…
+ …as QR-code
+ …encoded in text
+ Set Ring-Settings to %1$s.
+ Rewired Reflector.
+ Set Plugboard configuration.
+ Generate configuration from passphrase %1$s.
+ Restored configuration from coded state.
+ No changes.
+ Enigma reset.
+ Enigma set to random configuration.
+ Copied to clipboard
-
+ %1$s:%2$s
+
+
+ I
+ II
+ III
+
+ IIIIIIIVV
-
- A
- B
- C
-
-
- A
- B
- C
- D
- E
- F
- G
- H
+ I
- J
- K
- L
- M
- N
- O
- P
- Q
- R
- S
- T
- U
+ II
+ III
+ IVV
- W
- X
- Y
- Z
+ VI
+ VII
+ VIII
-
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
+
+ A
+ B
+ C
+
+ B
+ C
+
+
+ \u03B2
+ \u03B3
+
+
diff --git a/app/src/main/res/values/strings_activity_settings.xml b/app/src/main/res/values/strings_activity_settings.xml
index 5788800..33f88a0 100644
--- a/app/src/main/res/values/strings_activity_settings.xml
+++ b/app/src/main/res/values/strings_activity_settings.xml
@@ -1,12 +1,74 @@
Settings
-
Simulation
+ Enigma Model
+ Which model do you want to simulate?
+
+ I (Army, Airforce)
+ M3 (Army, Navy)
+ M4 (\"Shark\", Navy)
+ G31/A865 (Defense)
+ G312 (Defense)
+ G260 (Defense)
+ D (Commercial)
+ K
+ Swiss-K
+ Swiss-K (Airforce)
+ KD
+ R (\"Rocket\", Railway)
+ T (\"Tirpitz\", Japan)
+
+
+ I
+ M3
+ M4
+ G31
+ G312
+ G260
+ D
+ K
+ KS
+ KSA
+ KD
+ R
+ T
+
- Simulate Anomaly
- The double step anomaly causes the middle rotor
- to rotate twice, if it is one step before its turnover point.
-
+ Input Preparation
+ Number spelling language
+ Language, in which numbers are spelled.
+
+ German
+ English
+ French
+ Spanish
+ Italian
+ No replacing
+
+
+ de
+ en
+ fr
+ sp
+ it
+ no
+
+
+ Appearance
+ Message Formatting
+ Do you want to split the message up into blocks?
+
+ No division
+ Blocks of 4
+ Blocks of 5
+ Blocks of 6
+
+
+ no
+ 4
+ 5
+ 6
+
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 8e64f09..a36306d 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -1,8 +1,4 @@
+
-
-
-
-
+
diff --git a/app/src/main/res/xml/pref_page.xml b/app/src/main/res/xml/pref_page.xml
index 727c065..bcb6cb9 100644
--- a/app/src/main/res/xml/pref_page.xml
+++ b/app/src/main/res/xml/pref_page.xml
@@ -2,11 +2,33 @@
-
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index d3ff69d..35171ac 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,11 +1,11 @@
-// Top-level build file where you can add configuration options common to all sub-projects/modules.
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:1.1.0'
+ classpath 'com.android.tools.build:gradle:2.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
diff --git a/build/intermediates/dex-cache/cache.xml b/build/intermediates/dex-cache/cache.xml
deleted file mode 100644
index a32e652..0000000
--- a/build/intermediates/dex-cache/cache.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/build/intermediates/model_data.bin b/build/intermediates/model_data.bin
deleted file mode 100644
index 36e6fab..0000000
Binary files a/build/intermediates/model_data.bin and /dev/null differ
diff --git a/de.vanitasvitae.enigmandroid.txt b/de.vanitasvitae.enigmandroid.txt
deleted file mode 100644
index 0876ffb..0000000
--- a/de.vanitasvitae.enigmandroid.txt
+++ /dev/null
@@ -1,46 +0,0 @@
-Categories:Science & Education
-License:GPLv2
-Web Site: https://github.com/vanitasvitae/EnigmAndroid/wiki/EnigmAndroid
-Source Code: https://github.com/vanitasvitae/EnigmAndroid
-Issue Tracker: https://github.com/vanitasvitae/EnigmAndroid/issues
-Summary: Simulation of the Enigma Machine
-Description:
-This is a simulation of the famous Enigma cipher machine used in the twentieth century and especially in the Second World War.
-The Enigma Machine was a typewriter-like machine with 26 keys and corresponding lamps. It used a set of mechanical Rotors to achieve polyalphabetic substitution.
-
-The Enigma Machine was broken during the second world war by Marian Rejewski, Jerzy Różycki and Henryk Zygalski, who created a Machine called "Bomba" which could break the enigma code.
-After Germany invaded Poland, the british mathematician Alan Turing (known for his work on theoretical computer science) succeeded in completely breaking the Enigma.
-
-Features:
-* Authentic Rotors
-* Ringsettings
-* Double Step Anomaly
-* Working plugboard
-
-More Information about the historical Enigma can be found on https://de.wikipedia.org/wiki/Enigma_%28Maschine%29
-.
-
-
-Repo Type:git
-Repo:https://github.com/vanitasvitae/EnigmAndroid
-
-Build:0.1.1-18.02.2015-beta,6
- commit=707cdfcff66aababce83af1769ba9d8527067c8d
- subdir=app
- gradle=yes
-
-Build:0.1.1-23.02.2015-beta,7
- commit=965aee43dd998c7f0fc70093e53ac05fd7311eab
- subdir=app
- gradle=yes
-
-Build:0.1.2-24.02.2015-beta,8
- commit=310e44029ae1ee3754c630d923cb8f5468ea26d3
- subdir=app
- gradle=yes
-
-Auto Update Mode:None
-Update Check Mode:Tags
-Current Version:0.1.2-24.02.2015-beta
-Current Version Code:8
-
diff --git a/fastlane/metadata/android/de/full_description.txt b/fastlane/metadata/android/de/full_description.txt
new file mode 100644
index 0000000..4eefe24
--- /dev/null
+++ b/fastlane/metadata/android/de/full_description.txt
@@ -0,0 +1,11 @@
+Die Enigma ist ein Schreibmaschinen-ähnliches Gerät, welches eine Reihe von Walzen und Steckern besitzt, mit denen per polyalphabetischer Ersetzung Texte und Nachrichten verschlüsselt werden können.
+
+EnigmAndroid legt großen Wert darauf, die Verschlüsselungsroutinen realistisch und historisch genau umzusetzen und verzichtet dabei auf authentische Optik. Ziel der Anwendung ist es, historische Nachrichten korrekt entschlüsseln zu können.
+
+Funktionen:
+
+* Wachsende Anzahl an authentischen Enigma Modellen
+* Verschlüssle beliebige Texte indem du sie aus anderen Anwendungen heraus mit EnigmAndroid teilst
+* Teile verschlüsselte Texte mit anderen Apps
+
+Weitere Informationen über die histosche Enigma Maschine können unter anderem auf Wikipedia gefunden werden.
diff --git a/fastlane/metadata/android/de/short_description.txt b/fastlane/metadata/android/de/short_description.txt
new file mode 100644
index 0000000..4e40676
--- /dev/null
+++ b/fastlane/metadata/android/de/short_description.txt
@@ -0,0 +1 @@
+Simulation der Enigma Verschlüsselungsmaschine
diff --git a/fastlane/metadata/android/en-US/featureGraphic.png b/fastlane/metadata/android/en-US/featureGraphic.png
new file mode 100644
index 0000000..b3d627c
Binary files /dev/null and b/fastlane/metadata/android/en-US/featureGraphic.png differ
diff --git a/fastlane/metadata/android/en-US/full_description.txt b/fastlane/metadata/android/en-US/full_description.txt
new file mode 100644
index 0000000..82502a2
--- /dev/null
+++ b/fastlane/metadata/android/en-US/full_description.txt
@@ -0,0 +1,11 @@
+The Enigma Machine is a typewriter-like machine, which uses a set of mechanical Rotors to achieve polyalphabetic substitution to encrypt texts.
+
+EnigmAndroid lays its focus on realistic and authentic encryption, rather than on authentic look and feel. The goal is to have an application that can decrypt historic messages given the correct settings.
+
+Features:
+
+* Growing number of authentic Enigma-Models
+* Quickly encrypt any text by sharing it from any other app
+* Also quickly share encrypted texts from EnigmAndroid to any other app
+
+More Information about the historical Enigma can be found on Wikipedia] (german).
diff --git a/fastlane/metadata/android/en-US/images/phoneScreenshots/shot_01.png b/fastlane/metadata/android/en-US/images/phoneScreenshots/shot_01.png
new file mode 100644
index 0000000..2b7010e
Binary files /dev/null and b/fastlane/metadata/android/en-US/images/phoneScreenshots/shot_01.png differ
diff --git a/fastlane/metadata/android/en-US/images/phoneScreenshots/shot_02.png b/fastlane/metadata/android/en-US/images/phoneScreenshots/shot_02.png
new file mode 100644
index 0000000..e134140
Binary files /dev/null and b/fastlane/metadata/android/en-US/images/phoneScreenshots/shot_02.png differ
diff --git a/fastlane/metadata/android/en-US/images/phoneScreenshots/shot_03.png b/fastlane/metadata/android/en-US/images/phoneScreenshots/shot_03.png
new file mode 100644
index 0000000..5ede482
Binary files /dev/null and b/fastlane/metadata/android/en-US/images/phoneScreenshots/shot_03.png differ
diff --git a/fastlane/metadata/android/en-US/images/phoneScreenshots/shot_04.png b/fastlane/metadata/android/en-US/images/phoneScreenshots/shot_04.png
new file mode 100644
index 0000000..bccf35f
Binary files /dev/null and b/fastlane/metadata/android/en-US/images/phoneScreenshots/shot_04.png differ
diff --git a/fastlane/metadata/android/en-US/images/tenInchScreenshots/shot_11.png b/fastlane/metadata/android/en-US/images/tenInchScreenshots/shot_11.png
new file mode 100644
index 0000000..60403b3
Binary files /dev/null and b/fastlane/metadata/android/en-US/images/tenInchScreenshots/shot_11.png differ
diff --git a/fastlane/metadata/android/en-US/images/tenInchScreenshots/shot_12.png b/fastlane/metadata/android/en-US/images/tenInchScreenshots/shot_12.png
new file mode 100644
index 0000000..1921fdb
Binary files /dev/null and b/fastlane/metadata/android/en-US/images/tenInchScreenshots/shot_12.png differ
diff --git a/fastlane/metadata/android/en-US/images/tenInchScreenshots/shot_13.png b/fastlane/metadata/android/en-US/images/tenInchScreenshots/shot_13.png
new file mode 100644
index 0000000..affa0a1
Binary files /dev/null and b/fastlane/metadata/android/en-US/images/tenInchScreenshots/shot_13.png differ
diff --git a/fastlane/metadata/android/en-US/images/tenInchScreenshots/shot_14.png b/fastlane/metadata/android/en-US/images/tenInchScreenshots/shot_14.png
new file mode 100644
index 0000000..2cb94c4
Binary files /dev/null and b/fastlane/metadata/android/en-US/images/tenInchScreenshots/shot_14.png differ
diff --git a/fastlane/metadata/android/en-US/short_description.txt b/fastlane/metadata/android/en-US/short_description.txt
new file mode 100644
index 0000000..f726cf3
--- /dev/null
+++ b/fastlane/metadata/android/en-US/short_description.txt
@@ -0,0 +1 @@
+Simulation of the Enigma Machine
diff --git a/fdroid-badge.png b/fdroid-badge.png
new file mode 100644
index 0000000..6955af3
Binary files /dev/null and b/fdroid-badge.png differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 0497007..75ea45c 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Tue Feb 24 19:07:06 CET 2015
+#Fri May 05 17:06:52 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
diff --git a/gradlew b/gradlew
index 91a7e26..f44cf0f 100644
--- a/gradlew
+++ b/gradlew
@@ -116,7 +116,7 @@ if $cygwin ; then
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
# We build the pattern for arguments to be converted via cygpath
- ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -name d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
diff --git a/local.properties b/local.properties
deleted file mode 100644
index 5297dba..0000000
--- a/local.properties
+++ /dev/null
@@ -1,11 +0,0 @@
-## This file is automatically generated by Android Studio.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must *NOT* be checked into Version Control Systems,
-# as it contains information specific to your local configuration.
-#
-# Location of the SDK. This is only used by Gradle.
-# For customization when using a Version Control System, please read the
-# header note.
-#Thu Mar 12 23:34:48 CET 2015
-sdk.dir=/media/Daten/android-sdk-linux