Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial import from http://svn.rayapps.com/plugins/oracle_ebs_authent…

  • Loading branch information...
commit 35252f073e5f87c0b3b27582e450c9a3e68561bc 0 parents
@ebeigarts authored
3  CHANGES
@@ -0,0 +1,3 @@
+== Version 0.1.0
+
+Initial release.
458 LICENCE
@@ -0,0 +1,458 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+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 and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, 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 library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete 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 distribute a copy of this License along with the
+Library.
+
+ 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.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+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 Library, 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.
+
+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 Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you 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.
+
+ If distribution of 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 satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be 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.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library 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.
+
+ 9. 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 Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+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 with
+this License.
+
+ 11. 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
+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 Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library 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 Library.
+
+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.
+
+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.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library 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.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser 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 Library
+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 Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+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.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "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
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. 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 LIBRARY 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
+LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
35 README
@@ -0,0 +1,35 @@
+== OracleEbsAuthentication
+
+This plugin provides Oracle E-Business Suite user authentication functionality.
+
+== Installation
+
+To install this plugin for your Ruby on Rails application do the following:
+
+script/plugin install http://svn.rayapps.com/plugins/oracle_ebs_authentication
+
+== Examples
+
+Simple example how to use the plugin for Oracle E-Business Suite user authentication:
+
+database_name = ActiveRecord::Base.connection.current_database
+authenticator = OracleEbsAuthentication::Authenticator.new(database_name)
+if authenticator.validate_user_password(login, password)
+ # user authenticated
+ if authenticator.user_reponsibilities.include? "System Administrator"
+ # user has System Administrator role
+ end
+ # ...
+else
+ # authentication failed
+end
+
+See other usage examples in RSpec examples in spec/oracle_ebs_authentication_spec.rb
+
+== Credits
+
+Copyright (C) 2007 Raimonds Simanovskis
+ http://blog.rayapps.com
+
+Oracle E-Business Suite authentication encryption algorythm was taken from Java source code
+by Mehmet Milci at http://www.milci.com/eappsjira and was rewritten in Ruby by Raimonds Simanovskis.
22 Rakefile
@@ -0,0 +1,22 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the oracle_ebs_authentication plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the oracle_ebs_authentication plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'OracleEbsAuthentication'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
2  init.rb
@@ -0,0 +1,2 @@
+# Include hook code here
+require "oracle_ebs_authentication"
118 lib/oracle_ebs_authentication.rb
@@ -0,0 +1,118 @@
+# OracleEbsAuthentication
+require "oci8"
+require "security"
+
+module OracleEbsAuthentication
+
+ class Authenticator
+ attr_accessor :user, :password
+ attr_reader :user_responsibilities, :user_id, :email
+
+ def initialize(db_name, gw_user="APPLSYSPUB", gw_password="PUB", fnd_name="APPS",
+ db_server_id=nil, module_name="FNDPUB")
+ @db_name = db_name
+ @gw_user = gw_user
+ @gw_password = gw_password
+ @fnd_name = fnd_name
+ @db_server_id = db_server_id
+ @module_name = module_name
+ @security = OracleEbsAuthentication::Security.new
+ end
+
+ def get_fnd_password(user = nil, password = nil)
+ @user = user.upcase unless user.blank?
+ @password = password.upcase unless password.blank?
+ if gw_connect
+ begin
+ cursor = @gw_connection.parse(<<-EOS
+ BEGIN
+ fnd_security_pkg.fnd_encrypted_pwd(:p_user,:p_server_id,:p_user_id,:p_efp,:p_module);
+ END;
+ EOS
+ )
+ cursor.bind_param(':p_user', @user, String, 100)
+ cursor.bind_param(':p_server_id', @db_server_id, String, 100)
+ cursor.bind_param(':p_user_id', nil, String, 100)
+ cursor.bind_param(':p_efp', nil, String, 100)
+ cursor.bind_param(':p_module', @module_name, String, 100)
+ cursor.exec
+ @user_id = cursor[':p_user_id']
+ @efp = cursor[':p_efp']
+ rescue OCIError
+ @user_id = nil
+ @efp = nil
+ end
+ gw_disconnect
+ @fnd_password = @efp ? @security.decrypt(@user.upcase + "/" + @password.upcase, @efp, false) : nil
+ else
+ @fnd_password = nil
+ end
+ end
+
+ def validate_user_password(user = nil, password = nil)
+ get_fnd_password(user, password) if user && password
+ return nil unless @fnd_password
+ if fnd_connect
+ cursor = @fnd_connection.parse(<<-EOS
+ SELECT encrypted_user_password, email_address
+ FROM fnd_user
+ WHERE user_id = :p_user_id
+ EOS
+ )
+ cursor.bind_param(':p_user_id', @user_id.to_i, Fixnum)
+ cursor.exec
+ r = cursor.fetch
+ @eup, @email = r[0], r[1]
+ cursor.close
+
+ @user_responsibilities = []
+ @fnd_connection.exec("SELECT r.responsibility_name
+ FROM fnd_user_resp_groups_all ur,
+ fnd_responsibility_vl r
+ WHERE ur.user_id = :p_user_id
+ AND TRUNC(SYSDATE) BETWEEN NVL(ur.start_date,TRUNC(SYSDATE)) AND NVL(ur.end_date, TRUNC(SYSDATE))
+ AND ur.responsibility_id = r.responsibility_id", @user_id.to_i) do |r|
+ @user_responsibilities << r[0]
+ end
+
+ fnd_disconnect
+
+ @security.decrypt(@fnd_password, @eup, false) == @password.upcase
+ else
+ false
+ end
+ end
+
+ private
+
+ def gw_connect
+ if @gw_connection = OCI8.new(@gw_user, @gw_password, @db_name)
+ true
+ else
+ false
+ end
+ rescue OCIError
+ false
+ end
+
+ def gw_disconnect
+ @gw_connection.logoff
+ end
+
+ def fnd_connect
+ if @fnd_connection = OCI8.new(@fnd_name, @fnd_password, @db_name)
+ return true
+ else
+ return false
+ end
+ rescue OCIError
+ false
+ end
+
+ def fnd_disconnect
+ @fnd_connection.logoff
+ end
+
+ end
+
+end
2,164 lib/security.rb
@@ -0,0 +1,2164 @@
+# The Java original source code was taken form http://www.milci.com/eappsjira
+# Original Java source is included in comments followed by corresponding Ruby code.
+# As original Java source is not documented then Ruby source code was done
+# as similar as possible to Java code to avoid differences in functionality.
+#
+
+require "digest/sha1"
+
+module OracleEbsAuthentication
+
+ # public class eBusinessSuiteSecurity {
+ class Security
+
+ # public eBusinessSuiteSecurity() {
+ # }
+ def initialize
+ end
+
+ # static String control(String s1, int i1, String s2) {
+ # return newControl(s1, s2, i1, 0);
+ # }
+ def control(s1, i1, s2)
+ return new_control(s1, s2, i1, 0)
+ end
+
+ #private static int[] a(byte abyte0[], int i1) {
+ def a(abyte0, i1)
+ # int ai[] = new int[16];
+ ai = [nil]*16
+ # int ai1[] = new int[5];
+ ai1 = [nil]*5
+ # u(ai1, null);
+ u(ai1, nil)
+ # int l1 = ai.length;
+ l1 = ai.length
+ # int k1 = 0;
+ k1 = 0
+ # int j2 = 0;
+ j2 = 0
+ # int j1;
+ # for (j1 = 0; j1 < (i1 & -4); j1 += 4) {
+ j1 = 0
+ while j1 < (i1 & -4)
+ # ai[k1] = abyte0[j2] | abyte0[j2 + 1] << 8 | abyte0[j2 + 2] << 16 |
+ # abyte0[j2 + 3] << 24;
+ ai[k1] = (abyte0[j2] | abyte0[j2 + 1] << 8 | abyte0[j2 + 2] << 16 |
+ abyte0[j2 + 3] << 24) & 0xffffffff
+ # if (++k1 == l1) {
+ # u(ai1, ai);
+ # k1 = 0;
+ # }
+ k1 +=1
+ if (k1 == l1)
+ u(ai1, ai)
+ k1 = 0
+ end
+ # j2 += 4;
+ j2 += 4
+ # }
+ j1 += 4
+ end
+ #
+ # j1 = i1 - j1;
+ j1 = i1 - j1
+ # if (j1 == 1) {
+ # ai[k1] = abyte0[j2] & 0xff | 0x8000;
+ # }
+ if (j1 == 1)
+ ai[k1] = abyte0[j2] & 0xff | 0x8000
+ # else
+ # if (j1 == 2) {
+ # ai[k1] = abyte0[j2] | abyte0[j2 + 1] << 8 | 0x800000;
+ # }
+ elsif (j1 == 2)
+ ai[k1] = (abyte0[j2] | abyte0[j2 + 1] << 8 | 0x800000) & 0xffffffff
+ # else
+ # if (j1 == 3) {
+ # ai[k1] = abyte0[j2] | abyte0[j2 + 1] << 8 | abyte0[j2 + 2] << 16 |
+ # 0x80000000;
+ # }
+ elsif (j1 == 3)
+ ai[k1] = (abyte0[j2] | abyte0[j2 + 1] << 8 | abyte0[j2 + 2] << 16 | 0x80000000) & 0xffffffff
+ # else {
+ # ai[k1] = 128;
+ # }
+ else
+ ai[k1] = 128
+ end
+ # if (++k1 >= l1 - 2) {
+ # while (k1 < l1) {
+ # ai[k1++] = 0;
+ # }
+ # u(ai1, ai);
+ # k1 = 0;
+ # }
+ k1 += 1
+ if (k1 >= l1 - 2)
+ while (k1 < l1)
+ ai[k1] = 0
+ k1 += 1
+ end
+ u(ai1,ai)
+ k1 = 0
+ end
+ # while (k1 < l1 - 2) {
+ # ai[k1++] = 0;
+ # }
+ while (k1 < l1 - 2)
+ ai[k1] = 0
+ k1 += 1
+ end
+ # int i2 = i1;
+ i2 = i1
+ # ai[k1++] = i2 >> 29 & 7;
+ ai[k1] = i2 >> 29 & 7
+ k1 += 1
+ # ai[k1] = i2 << 3;
+ ai[k1] = (i2 << 3) & 0xffffffff
+ # u(ai1, ai);
+ u(ai1, ai)
+ # return ai1;
+ return ai1
+ #}
+ end
+
+
+ # static String newCheck(String s1, String s2, boolean flag) {
+ def new_check(s1, s2, flag)
+ # if (s1 == null || s2 == null ||
+ # s2.length() >= "ZG_ENCRYPT_FAILED_".length() &&
+ # s2.substring(0,
+ # "ZG_ENCRYPT_FAILED_".length()).equals("ZG_ENCRYPT_FAILED_")) {
+ # return null;
+ # }
+ if (s1 == nil || s2 == nil ||
+ s2.length >= "ZG_ENCRYPT_FAILED_".length &&
+ s2[0, "ZG_ENCRYPT_FAILED_".length] == "ZG_ENCRYPT_FAILED_")
+ return nil
+ end
+ # byte abyte0[];
+ # try {
+ # abyte0 = s1.getBytes("UTF8");
+ # }
+ # catch (UnsupportedEncodingException _ex) {
+ # return null;
+ # }
+ abyte0 = s1.dup
+ # int l2 = abyte0.length;
+ l2 = abyte0.length
+ # int i3 = s2.length();
+ i3 = s2.length
+ # int i1 = 1;
+ i1 = 1
+ # byte byte0 = 2;
+ byte0 = 2
+ # int j1 = i3 - 2 - i1 * 2;
+ j1 = i3 - 2 - i1 * 2
+ # if (j1 <= 0) {
+ # return null;
+ # }
+ if (j1 <= 0)
+ return nil
+ end
+ # int k1 = (j1 / 16) * 8;
+ k1 = (j1 / 16) * 8
+ # if (k1 <= 0) {
+ # return null;
+ # }
+ if (k1 <= 0)
+ return nil
+ end
+ # int l1 = (j1 % 16) / 2;
+ l1 = (j1 % 16) / 2
+ # int i2 = l1 + i1;
+ i2 = l1 + i1
+ # int j2 = k1 - 1 - byte0;
+ j2 = k1 - 1 - byte0
+ # if (j2 <= 0) {
+ # return null;
+ # }
+ if (j2 <= 0)
+ return nil
+ end
+ # if (!s2.substring(0, 2).equals("ZG")) {
+ # return null;
+ # }
+ if (not s2[0, 2] == "ZG")
+ return nil
+ end
+ # String s3 = s2.substring(2);
+ s3 = s2[2..-1]
+ # byte abyte1[] = p(s3);
+ abyte1 = p(s3)
+ # byte abyte2[] = new byte[abyte1.length - i2];
+ abyte2 = "\0"*(abyte1.length - i2)
+ # byte abyte3[] = new byte[i2];
+ abyte3 = "\0"*i2
+ # System.arraycopy(abyte1, 0, abyte2, 0, abyte1.length - i2);
+ abyte2[0, abyte1.length - i2] = abyte1[0, abyte1.length - i2]
+ # System.arraycopy(abyte1, abyte1.length - i2, abyte3, 0, i2);
+ abyte3[0, i2] = abyte1[abyte1.length - i2, i2]
+ # byte abyte4[] = new byte[i2 + l2];
+ abyte4 = "\0"*(i2 + l2)
+ # System.arraycopy(abyte3, 0, abyte4, 0, i2);
+ abyte4[0, i2] = abyte3[0, i2]
+ # System.arraycopy(abyte0, 0, abyte4, i2, l2);
+ abyte4[i2, l2] = abyte0[0, l2]
+ # byte abyte5[] = v(null, abyte4, abyte2);
+ # puts "<br/>DEBUG new_check: abyte4=#{abyte4.inspect} abyte2=#{abyte2.unpack("H*")[0]}"
+ abyte5 = v(nil, abyte4, abyte2)
+ # if (abyte5 == null) {
+ # return null;
+ # }
+ if (abyte5 == nil)
+ # puts "<br/>DEBUG new_check: :nil6"
+ return nil
+ end
+ # int j3 = abyte5.length;
+ j3 = abyte5.length
+ # for (int k2 = byte0; k2 < abyte5.length; k2++) {
+ # if (abyte5[k2] != 0) {
+ # continue;
+ # }
+ # j3 = k2;
+ # break;
+ # }
+ for k2 in byte0...abyte5.length
+ if (abyte5[k2] != 0)
+ next
+ end
+ j3 = k2
+ break
+ end
+ #
+ # byte abyte6[] = new byte[j3 - byte0];
+ abyte6 = "\0"*(j3 - byte0)
+ # System.arraycopy(abyte5, byte0, abyte6, 0, j3 - byte0);
+ abyte6[0, j3 - byte0] = abyte5[byte0, j3 - byte0]
+ # String s4;
+ # try {
+ # s4 = new String(abyte6, "UTF8");
+ # }
+ # catch (UnsupportedEncodingException _ex) {
+ # return null;
+ # }
+ s4 = abyte6
+ # if (s4 != null && flag) {
+ # return w(s4, 0, flag);
+ # }
+ if (s4 != nil && flag)
+ return w(s4, 0, flag)
+ # else {
+ # return s4;
+ # }
+ else
+ return s4
+ end
+ # }
+ end
+
+ # private static void c(int ai[]) {
+ # ai[4] = j(ai[0], 5) + s(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0x8f1bbcdc;
+ # ai[2] = j(ai[1], 30);
+ # }
+ def c(ai)
+ ai[4] = j(ai[0], 5) + s(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0x8f1bbcdc
+ ai[2] = j(ai[1], 30)
+ end
+
+ # private static void d(byte abyte0[], int ai[]) {
+ # int ai1[] = new int[2];
+ # t(abyte0, ai1);
+ # F(ai1, ai);
+ # x(ai1, abyte0);
+ # }
+ def d(abyte0, ai)
+ ai1 = [nil]*2
+ t(abyte0, ai1)
+ # puts "<br/>DEBUG d: after t abyte0=#{abyte0.unpack("H*")[0]}"
+ # puts "<br/>DEBUG d: after t ai1=#{ai1.join(",")}"
+ f_(ai1, ai)
+ # puts "<br/>DEBUG d: after F ai1=#{ai1.join(",")}"
+ # puts "<br/>DEBUG d: after F ai=#{ai.join(",")}"
+ x(ai1, abyte0)
+ # puts "<br/>DEBUG d: after x ai1=#{ai1.join(",")}"
+ # puts "<br/>DEBUG d: after x abyte0=#{abyte0.unpack("H*")[0]}"
+ end
+
+ # private static byte[] e(int ai[]) {
+ # byte abyte0[] = new byte[4];
+ # byte abyte1[] = null;
+ # if (ai != null) {
+ # abyte1 = new byte[ai.length];
+ # for (int i1 = 0; i1 < ai.length; i1++) {
+ # abyte0[3] = (byte) (ai[i1] & 0xff);
+ # abyte0[2] = (byte) ( (ai[i1] & 0xff00) >> 8);
+ # abyte0[1] = (byte) ( (ai[i1] & 0xff0000) >> 16);
+ # abyte0[0] = (byte) ( (ai[i1] & 0xff000000) >> 24);
+ # abyte1[i1] = (byte) (abyte0[0] ^ abyte0[1] ^ abyte0[2] ^ abyte0[3]);
+ # }
+ #
+ # }
+ # return abyte1;
+ # }
+ def e(ai)
+ abyte0 = "\0"*4
+ abyte1 = nil
+ if (ai != nil)
+ abyte1 = "\0"*(ai.length)
+ for i1 in 0...ai.length
+ abyte0[3] = (ai[i1] & 0xff)
+ abyte0[2] = ( (ai[i1] & 0xff00) >> 8)
+ abyte0[1] = ( (ai[i1] & 0xff0000) >> 16)
+ abyte0[0] = ( (ai[i1] & 0xff000000) >> 24)
+ abyte1[i1] = (abyte0[0] ^ abyte0[1] ^ abyte0[2] ^ abyte0[3])
+ end
+ end
+ return abyte1
+ end
+
+ # private static byte f(int i1) {
+ # byte byte0 = 0;
+ # int j1 = (char) i1 & 0x40;
+ # if (j1 >= 1) {
+ # byte0 = (byte) ( (char) i1 - 55);
+ # }
+ # else {
+ # byte0 = (byte) ( (char) i1 & 0xf);
+ # }
+ # return byte0;
+ # }
+ def f(i1)
+ byte0 = 0
+ j1 = i1 & 0x40
+ if (j1 >= 1)
+ byte0 = i1 - 55
+ else
+ byte0 = i1 & 0xf
+ end
+ return byte0
+ end
+
+ # private static byte[] g(byte abyte0[], byte abyte1[]) {
+ def g(abyte0, abyte1)
+ # if (abyte0.length < 32) {
+ # return null;
+ # }
+ if (abyte0.length < 32)
+ # puts "<br/>DEBUG g: nil1"
+ return nil
+ end
+ # if (abyte1.length % 8 != 0) {
+ # return null;
+ # }
+ if (abyte1.length % 8 != 0)
+ # puts "<br/>DEBUG g: nil2"
+ return nil
+ end
+ # int i1 = abyte1.length / 8;
+ i1 = abyte1.length / 8
+ # byte abyte3[] = new byte[8];
+ abyte3 = "\0"*8
+ # byte abyte4[] = new byte[8];
+ abyte4 = "\0"*8
+ # byte abyte5[] = new byte[8];
+ abyte5 = "\0"*8
+ # byte abyte2[] = new byte[8];
+ abyte2 = "\0"*8
+ # System.arraycopy(abyte0, 0, abyte3, 0, 8);
+ abyte3[0,8] = abyte0[0, 8]
+ # System.arraycopy(abyte0, 8, abyte4, 0, 8);
+ abyte4[0,8] = abyte0[8, 8]
+ # System.arraycopy(abyte0, 16, abyte5, 0, 8);
+ abyte5[0,8] = abyte0[16, 8]
+ # System.arraycopy(abyte0, 24, abyte2, 0, 8);
+ abyte2[0,8] = abyte0[24, 8]
+ # int ai[] = l(abyte3, false);
+ ai = l(abyte3, false)
+ # int ai1[] = l(abyte4, true);
+ ai1 = l(abyte4, true)
+ # int ai2[] = l(abyte5, false);
+ ai2 = l(abyte5, false)
+ # byte abyte6[] = new byte[abyte1.length];
+ abyte6 = "\0"*(abyte1.length)
+ # int j1 = 0;
+ j1 = 0
+ # for (int k1 = 0; j1 < i1; k1 += 8) {
+ k1 = 0
+ while (j1 < i1)
+ # q(abyte1, k1, abyte6, k1, ai, ai1, ai2, abyte2, false);
+ q(abyte1, k1, abyte6, k1, ai, ai1, ai2, abyte2, false)
+ # puts "<br/>DEBUG g: after q() abyte6=#{abyte6.unpack("H*")[0]}"
+ # j1++;
+ j1 += 1
+ # }
+ k1 += 8
+ end
+ #
+ # byte byte0 = abyte6[abyte1.length - 1];
+ byte0 = abyte6[abyte1.length - 1]
+ # puts "<br/>DEBUG g: abyte1=#{abyte1.unpack("H*")[0]}"
+ # puts "<br/>DEBUG g: abyte1.length=#{abyte1.length}"
+ # puts "<br/>DEBUG g: abyte6=#{abyte6.unpack("H*")[0]}"
+ # if (byte0 < 1 || byte0 > 8) {
+ # return null;
+ # }
+ if (byte0 < 1 || byte0 > 8)
+ # puts "<br/>DEBUG g: nil3"
+ # puts "<br/>DEBUG g: byte0=#{byte0}"
+ return nil
+ end
+ # for (int l1 = abyte1.length - byte0; l1 < abyte1.length; l1++) {
+ for l1 in (abyte1.length-byte0)...abyte1.length
+ # if (abyte6[l1] != byte0) {
+ # return null;
+ # }
+ if (abyte6[l1] != byte0)
+ # puts "<br/>DEBUG g: nil4"
+ return nil
+ end
+ # }
+ end
+ #
+ # byte abyte7[] = new byte[abyte1.length - byte0];
+ abyte7 = "\0"*(abyte1.length - byte0)
+ # System.arraycopy(abyte6, 0, abyte7, 0, abyte1.length - byte0);
+ abyte7[0, abyte1.length - byte0] = abyte6[0, abyte1.length - byte0]
+ # return abyte7;
+ # puts "<br/>DEBUG g: abyte7=#{abyte7.unpack("H*")[0]}"
+ return abyte7
+ # }
+ end
+
+ # private static void h(int ai[]) {
+ # ai[4] = j(ai[0], 5) + o(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0xca62c1d6;
+ # ai[2] = j(ai[1], 30);
+ # }
+ def h(ai)
+ ai[4] = j(ai[0], 5) + o(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0xca62c1d6
+ ai[2] = j(ai[1], 30)
+ end
+
+ # private static byte[] i(byte abyte0[], byte abyte1[], byte abyte2[]) {
+ # return G(y(abyte0, abyte1), abyte2);
+ # }
+ def i(abyte0, abyte1, abyte2)
+ return g_(y(abyte0, abyte1), abyte2)
+ end
+
+ # private static int j(int i1, int j1) {
+ # return i1 << j1 | i1 >>> 32 - j1;
+ # }
+ # TODO: check impact of >>> substitution with >>
+ def j(i1, j1)
+ return (i1 << j1 | i1 >> 32 - j1) & 0xffffffff
+ end
+
+ # private static byte[] k(byte abyte0[], byte abyte1[], int i1) {
+ def k(abyte0, abyte1, i1)
+ # if (abyte0 == null || abyte1 == null) {
+ # return null;
+ # }
+ if (abyte0 == nil || abyte1 == nil)
+ return nil
+ # else {
+ # int ai[] = a(abyte0, abyte0.length);
+ # byte abyte2[] = e(ai);
+ # byte abyte3[] = new byte[258];
+ # B(abyte3, abyte2, null, 5);
+ # byte abyte4[] = new byte[i1];
+ # B(abyte3, abyte1, abyte4, i1);
+ # return abyte4;
+ # }
+ else
+ ai = a(abyte0, abyte0.length)
+ abyte2 = e(ai)
+ abyte3 = "\0"*258
+ b_(abyte3, abyte2, nil, 5)
+ abyte4 = "\0"*i1
+ b_(abyte3, abyte1, abyte4, i1)
+ return abyte4
+ end
+ # }
+ end
+
+ # private static int[] l(byte abyte0[], boolean flag) {
+ def l(abyte0, flag)
+ # byte abyte1[] = new byte[56];
+ abyte1 = "\0"*56
+ # byte abyte2[] = new byte[56];
+ abyte2 = "\0"*56
+ # int ai[] = new int[32];
+ ai = [nil]*32
+ # for (int j1 = 0; j1 < 56; j1++) {
+ # byte byte0 = V[j1];
+ # int l2 = byte0 & 7;
+ # abyte1[j1] = (byte) ( (abyte0[byte0 >>> 3] & bi[l2]) == 0 ? 0 : 1);
+ # }
+ # TODO: check impact of >>> substitution with >>
+ for j1 in 0...56
+ byte0 = V[j1]
+ l2 = byte0 & 7
+ abyte1[j1] = ( (abyte0[byte0 >> 3] & Bi[l2]) == 0 ? 0 : 1)
+ end
+ #
+ # for (int i1 = 0; i1 < 16; i1++) {
+ for i1 in 0...16
+ # int i3;
+ # if (flag) {
+ # i3 = i1 << 1;
+ # }
+ if (flag)
+ i3 = i1 << 1
+ # else {
+ # i3 = 15 - i1 << 1;
+ # }
+ else
+ i3 = 15 - i1 << 1
+ end
+ # int j3 = i3 + 1;
+ j3 = i3 + 1
+ # ai[i3] = ai[j3] = 0;
+ ai[i3] = ai[j3] = 0
+ # for (int k1 = 0; k1 < 28; k1++) {
+ for k1 in 0...28
+ # int j2 = k1 + bb[i1];
+ j2 = k1 + Bb[i1]
+ # if (j2 < 28) {
+ # abyte2[k1] = abyte1[j2];
+ # }
+ if (j2 < 28)
+ abyte2[k1] = abyte1[j2]
+ # else {
+ # abyte2[k1] = abyte1[j2 - 28];
+ # }
+ else
+ abyte2[k1] = abyte1[j2 - 28]
+ end
+ # }
+ end
+ #
+ # for (int l1 = 28; l1 < 56; l1++) {
+ for l1 in 28...56
+ # int k2 = l1 + bb[i1];
+ k2 = l1 + Bb[i1]
+ # if (k2 < 56) {
+ # abyte2[l1] = abyte1[k2];
+ # }
+ if (k2 < 56)
+ abyte2[l1] = abyte1[k2]
+ # else {
+ # abyte2[l1] = abyte1[k2 - 28];
+ # }
+ else
+ abyte2[l1] = abyte1[k2 - 28]
+ end
+ # }
+ end
+ #
+ # for (int i2 = 0; i2 < 24; i2++) {
+ for i2 in 0...24
+ # if (abyte2[S[i2]] != 0) {
+ # ai[i3] |= W[i2];
+ # }
+ if (abyte2[S[i2]] != 0)
+ ai[i3] |= W[i2]
+ end
+ # if (abyte2[S[i2 + 24]] != 0) {
+ # ai[j3] |= W[i2];
+ # }
+ if (abyte2[S[i2 + 24]] != 0)
+ ai[j3] |= W[i2]
+ end
+ # }
+ end
+ #
+ # }
+ end
+ #
+ # return C(ai);
+ return c_(ai)
+ # }
+ end
+
+ # static String oldControl(String s1, String s2, int i1) {
+ def old_control(s1, s2, i1)
+ # if (s1 == null || s2 == null) {
+ # return null;
+ # }
+ if (s1 == nil || s2 == nil)
+ return nil
+ end
+ # byte abyte0[] = A(s1.toCharArray());
+ abyte0 = a_(s1.dup)
+ # int j1 = s2.length();
+ #j1 = s2.chars.length
+ j1 = s2.length
+
+ # if (j1 > i1 - 1) {
+ # j1 = i1 - 1;
+ # }
+ if (j1 > i1 - 1)
+ j1 = i1 - 1
+ end
+ # Random random = new Random();
+ # RSI: no need to create object here
+ # int k1 = i1 - j1 - 1;
+ k1 = i1 - j1 - 1
+ # int ai[] = new int[k1];
+ ai = [nil]*k1
+ # for (int l1 = 0; l1 < k1; l1++) {
+ # ai[l1] = random.nextInt();
+ #
+ # }
+ # TODO: substitute Java random.nextInt() with ruby
+ for l1 in 0..k1
+ # simulation of random.nextInt()
+ ai[l1] = rand(2**32)-2**31
+ end
+ # byte abyte1[] = e(ai);
+ abyte1 = e(ai)
+ # byte abyte2[] = A( (new String(s2 + '\0')).toCharArray());
+ abyte2 = a_( (s2 + "\0") )
+ # byte abyte3[] = new byte[k1 + abyte2.length];
+ abyte3 = "\0"*(k1 + abyte2.length)
+ # System.arraycopy(abyte2, 0, abyte3, 0, abyte2.length);
+ abyte3[0, abyte2.length] = abyte2[0, abyte2.length]
+ # System.arraycopy(abyte1, 0, abyte3, abyte2.length, k1);
+ abyte3[abyte2.length, k1] = abyte1[0, k1]
+ # byte abyte4[] = k(abyte0, abyte3, i1);
+ abyte4 = k(abyte0, abyte3, i1)
+ # return z(abyte4);
+ return z(abyte4)
+ # }
+ end
+
+ # private static char[] m(byte abyte0[]) {
+ def m(abyte0)
+ # char ac1[];
+ # label0: {
+ while true
+ # if (abyte0 == null) {
+ # return null;
+ # }
+ if (abyte0 == nil)
+ return nil
+ end
+ # char ac[] = new char[abyte0.length];
+ ac = "\0"*(abyte0.length)
+ # int i1 = 0;
+ i1 = 0
+ # boolean flag = false;
+ flag = false
+ # boolean flag1 = false;
+ flag1 = false
+ # ac1 = null;
+ ac1 = nil
+ # try {
+ begin
+ # for (int j1 = 0; j1 < abyte0.length; j1++) {
+ break_value = for j1 in 0...abyte0.length do
+ # byte byte0 = abyte0[j1];
+ byte0 = abyte0[j1]
+ # if ( (byte0 & 0x80) == 0) {
+ # ac[i1++] = (char) byte0;
+ # if ( (char) byte0 == 0) {
+ # break;
+ # }
+ # continue;
+ # }
+ if ( (byte0 & 0x80) == 0)
+ ac[i1] = byte0
+ i1 += 1
+ if ( byte0 == 0)
+ break
+ end
+ next
+ end
+ # if ( (byte0 & 0xe0) == 192) {
+ # char c1 = (char) ( (byte0 & 0x1f) << 6 & 0x7c0);
+ # byte0 = abyte0[++j1];
+ # if ( (byte0 & 0x80) == 128) {
+ # c1 |= byte0 & 0x3f;
+ # ac[i1++] = c1;
+ # continue;
+ # }
+ # break label0;
+ # }
+ if ( (byte0 & 0xe0) == 192)
+ c1 = ( (byte0 & 0x1f) << 6 & 0x7c0)
+ j1 += 1
+ byte0 = abyte0[j1]
+ if ( (byte0 & 0x80) == 128)
+ c1 |= byte0 & 0x3f
+ ac[i1] = c1
+ i1 += 1
+ next
+ end
+ break :label0
+ end
+ # if ( (byte0 & 0xf0) != 224) {
+ # continue;
+ # }
+ if ( (byte0 & 0xf0) != 224)
+ continue
+ end
+ # char c2 = (char) ( (byte0 & 0xf) << 12 & 0xf000);
+ c2 = ( (byte0 & 0xf) << 12 & 0xf000)
+ # byte0 = abyte0[++j1];
+ j1 += 1
+ byte0 = abyte0[j1]
+ # if ( (byte0 & 0x80) != 128) {
+ # break label0;
+ # }
+ if ( (byte0 & 0x80) != 128)
+ break :label0
+ end
+ # c2 |= (byte0 & 0x3f) << 6 & 0xfc0;
+ c2 |= (byte0 & 0x3f) << 6 & 0xfc0
+ # byte0 = abyte0[++j1];
+ j1 += 1
+ byte0 = abyte0[j1]
+ # if ( (byte0 & 0x80) != 128) {
+ # break label0;
+ # }
+ if ( (byte0 & 0x80) != 128)
+ break :label0
+ end
+ # c2 |= byte0 & 0x3f;
+ c2 |= byte0 & 0x3f
+ # ac[i1++] = c2;
+ ac[i1] = c2
+ i1 += 1
+ # }
+ end
+ # RSI: jump back to label0 if brake was called with :label0
+ if break_value == :label0
+ next
+ end
+ #
+ # ac1 = new char[i1];
+ ac1 = "\0"*i1
+ # System.arraycopy(ac, 0, ac1, 0, i1);
+ ac1[0,i1] = ac[0,i1]
+ # }
+ # catch (ArrayIndexOutOfBoundsException _ex) {
+ # ac1 = null;
+ # }
+ end
+ # TODO: when this exception could happen?
+ # }
+ # return ac1;
+ # }
+ # RSI: if we are here then we should return value and escape endless loop
+ return ac1
+ end
+ end
+
+
+ # private static int n(int i1, int j1, int k1) {
+ # return i1 ^ j1 ^ k1;
+ # }
+ def n(i1, j1, k1)
+ return i1 ^ j1 ^ k1
+ end
+
+ # private static int o(int i1, int j1, int k1) {
+ # return i1 ^ j1 ^ k1;
+ # }
+ def o(i1, j1, k1)
+ return i1 ^ j1 ^ k1
+ end
+
+ # static String control(String s1, String s2, int i1) {
+ # return newControl(s1, s2, 0, i1);
+ # }
+ def control(s1, s2, i1)
+ return new_control(s1, s2, 0, i1)
+ end
+
+ # private static byte[] p(String s1) {
+ def p(s1)
+ # boolean flag = false;
+ flag = false
+ # boolean flag1 = false;
+ flag1 = false
+ # int i1 = 0;
+ i1 = 0
+ # int j1 = 0;
+ j1 = 0
+ # byte abyte0[] = null;
+ abyte0 = nil
+ # if (s1 == null) {
+ # return null;
+ # }
+ if (s1 == nil)
+ return nil
+ end
+ # int k1 = s1.length() / 2;
+ k1 = s1.length / 2
+ # if (k1 > 0) {
+ if (k1 > 0)
+ # abyte0 = new byte[k1];
+ abyte0 = "\0"*k1
+ # for (; k1 > 0; k1--) {
+ while (k1 > 0)
+ # char c1 = s1.charAt(i1++);
+ #c1 = s1.chars[i1]
+ c1 = s1[i1]
+ i1 += 1
+ # char c2 = s1.charAt(i1++);
+ #c2 = s1.chars[i1]
+ c2 = s1[i1]
+ i1 += 1
+ # abyte0[j1++] = (byte) (f(c1) << 4 | f(c2));
+ abyte0[j1] = (f(c1) << 4 | f(c2)) & 0xffffffff
+ j1 += 1
+ # }
+ k1 -= 1
+ end
+ #
+ # }
+ end
+ # return abyte0;
+ return abyte0
+ # }
+ end
+
+ # private static void q(byte abyte0[], int i1, byte abyte1[], int j1, int ai[],
+ # int ai1[], int ai2[], byte abyte2[],
+ # boolean flag) {
+ def q(abyte0, i1, abyte1, j1, ai,
+ ai1, ai2, abyte2,
+ flag)
+ # byte abyte3[] = new byte[8];
+ abyte3 = "\0"*8
+ # System.arraycopy(abyte0, i1, abyte3, 0, 8);
+ abyte3[0, 8] = abyte0[i1, 8]
+ # if (!flag) {
+ # d(abyte3, ai2);
+ # d(abyte3, ai1);
+ # d(abyte3, ai);
+ # D(abyte3, abyte2, abyte1, j1);
+ # System.arraycopy(abyte0, i1, abyte2, 0, 8);
+ # return;
+ # }
+ if (!flag)
+ # puts "<br/>DEBUG q: initial abyte3=#{abyte3.unpack("H*")[0]}"
+ # puts "<br/>DEBUG q: initial ai2=#{ai2.join(',')}"
+ # puts "<br/>DEBUG q: initial ai1=#{ai1.join(',')}"
+ # puts "<br/>DEBUG q: initial ai=#{ai.join(',')}"
+ d(abyte3, ai2)
+ # puts "<br/>DEBUG q: abyte3=#{abyte3.unpack("H*")[0]}"
+ d(abyte3, ai1)
+ # puts "<br/>DEBUG q: abyte3=#{abyte3.unpack("H*")[0]}"
+ d(abyte3, ai)
+ # puts "<br/>DEBUG q: abyte3=#{abyte3.unpack("H*")[0]}"
+ d_(abyte3, abyte2, abyte1, j1)
+ # puts "<br/>DEBUG q: abyte3=#{abyte3.unpack("H*")[0]}"
+ # puts "<br/>DEBUG q: abyte2=#{abyte2.unpack("H*")[0]}"
+ # puts "<br/>DEBUG q: abyte1=#{abyte1.unpack("H*")[0]}"
+ abyte2[0, 8] = abyte0[i1, 8]
+ return
+ # else {
+ # D(abyte3, abyte2, abyte3, 0);
+ # d(abyte3, ai);
+ # d(abyte3, ai1);
+ # d(abyte3, ai2);
+ # System.arraycopy(abyte3, 0, abyte2, 0, 8);
+ # System.arraycopy(abyte3, 0, abyte1, j1, 8);
+ # return;
+ # }
+ else
+ d_(abyte3, abyte2, abyte3, 0);
+ d(abyte3, ai);
+ d(abyte3, ai1);
+ d(abyte3, ai2);
+ abyte2[0, 8] = abyte3[0, 8]
+ abyte1[j1, 8] = abyte3[0, 8]
+ return
+ end
+ # }
+ end
+
+ # private static int r(int i1, int j1, int k1) {
+ # return i1 & j1 | ~i1 & k1;
+ # }
+ def r(i1, j1, k1)
+ return i1 & j1 | ~i1 & k1
+ end
+
+ # private static int s(int i1, int j1, int k1) {
+ # return i1 & j1 | i1 & k1 | j1 & k1;
+ # }
+ def s(i1, j1, k1)
+ return i1 & j1 | i1 & k1 | j1 & k1
+ end
+
+ # static String hash(String s1) {
+ def hash(s1)
+ # if (s1 == null) {
+ # return null;
+ # }
+ if (s1 == nil)
+ return nil
+ end
+ # byte abyte0[];
+ # try {
+ # abyte0 = s1.getBytes("UTF8");
+ # }
+ # catch (UnsupportedEncodingException _ex) {
+ # return null;
+ # }
+ abyte0 = s1.dup
+ # byte abyte1[] = y(null, abyte0);
+ abyte1 = y(nil, abyte0)
+ # return z(abyte1);
+ return z(abyte1)
+ # }
+ end
+
+ # static String newControl(String s1, String s2, int i1, int j1) {
+ def new_control(s1, s2, i1, j1)
+ # if (s1 == null || s2 == null) {
+ # return "ZG_ENCRYPT_FAILED_BADINPUT";
+ # }
+ if (s1 == nil || s2 == nil)
+ return "ZG_ENCRYPT_FAILED_BADINPUT"
+ end
+ # int k1;
+ # if (i1 > 0) {
+ # k1 = i1;
+ # }
+ if (i1 > 0)
+ k1 = i1
+ # else
+ # if (j1 == 32) {
+ # k1 = 100;
+ # }
+ elsif (j1 == 32)
+ k1 = 100
+ # else
+ # if (j1 < 32 && j1 == s2.length()) {
+ # k1 = 100;
+ # }
+ elsif (j1 < 32 && j1 == s2.length())
+ k1 = 100
+ # else {
+ # byte abyte1[];
+ # try {
+ # abyte1 = s2.getBytes("UTF8");
+ # }
+ # catch (UnsupportedEncodingException _ex) {
+ # return "ZG_ENCRYPT_FAILED_MISC";
+ # }
+ # k1 = ( (abyte1.length + 10) / 8) * 16 + 4 + 14;
+ # }
+ else
+ abyte1 = s2.dup
+ k1 = ( (abyte1.length + 10) / 8) * 16 + 4 + 14
+ end
+ # int l1 = 1;
+ l1 = 1
+ # byte byte0 = 2;
+ byte0 = 2
+ # int i2 = k1 - 2 - l1 * 2;
+ i2 = k1 - 2 - l1 * 2
+ # if (i2 <= 0) {
+ # return "ZG_ENCRYPT_FAILED_SMALLBUF";
+ # }
+ if (i2 <= 0)
+ return "ZG_ENCRYPT_FAILED_SMALLBUF"
+ end
+ # int j2 = (i2 / 16) * 8;
+ j2 = (i2 / 16) * 8
+ # if (j2 <= 0) {
+ # return "ZG_ENCRYPT_FAILED_SMALLBUF";
+ # }
+ if (j2 <= 0)
+ return "ZG_ENCRYPT_FAILED_SMALLBUF"
+ end
+ # int k2 = (i2 % 16) / 2;
+ k2 = (i2 % 16) / 2
+ # int l2 = k2 + l1;
+ l2 = k2 + l1
+ # int i3 = j2 - 1 - byte0;
+ i3 = j2 - 1 - byte0
+ # if (i3 <= 0) {
+ # return "ZG_ENCRYPT_FAILED_SMALLBUF";
+ # }
+ if (i3 <= 0)
+ return "ZG_ENCRYPT_FAILED_SMALLBUF"
+ end
+ # byte abyte0[];
+ # byte abyte2[];
+ # try {
+ # abyte0 = s1.getBytes("UTF8");
+ # abyte2 = s2.getBytes("UTF8");
+ # }
+ # catch (UnsupportedEncodingException _ex) {
+ # return "ZG_ENCRYPT_FAILED_MISC";
+ # }
+ abyte0 = s1.dup
+ abyte2 = s2.dup
+ # int j3 = abyte0.length;
+ j3 = abyte0.length
+ # int k3 = abyte2.length;
+ k3 = abyte2.length
+ # if (k3 > i3) {
+ # return "ZG_ENCRYPT_FAILED_CHARSET_CLIP";
+ # }
+ if (k3 > i3)
+ return "ZG_ENCRYPT_FAILED_CHARSET_CLIP"
+ end
+ # Random random = new Random();
+ # int ai[] = new int[l2];
+ ai = [nil]*l2
+ # for (int l3 = 0; l3 < l2; l3++) {
+ # ai[l3] = random.nextInt();
+ #
+ # }
+ for l3 in 0...l2
+ ai[l3] = rand(2**32)-2**31
+ end
+ # byte abyte3[] = e(ai);
+ abyte3 = e(ai)
+ # ai = null;
+ ai = nil
+ # byte byte1 = byte0;
+ byte1 = byte0
+ # ai = new int[byte1];
+ ai = [nil]*byte1
+ # for (int i4 = 0; i4 < byte1; i4++) {
+ # ai[i4] = random.nextInt();
+ #
+ # }
+ for i4 in 0...byte1
+ ai[i4] = rand(2**32)-2**31
+ end
+ # byte abyte4[] = e(ai);
+ abyte4 = e(ai)
+ # ai = null;
+ ai = nil
+ # int j4 = i3 - k3;
+ j4 = i3 - k3
+ # ai = new int[j4];
+ ai = [nil]*j4
+ # for (int k4 = 0; k4 < j4; k4++) {
+ for k4 in 0...j4
+ # if (k4 == 0) {
+ # ai[k4] = 0;
+ # }
+ if (k4 == 0)
+ ai[k4] = 0
+ # else {
+ # ai[k4] = random.nextInt();
+ #
+ # }
+ else
+ ai[k4] = rand(2**32)-2**31
+ end
+ # }
+ end
+ # byte abyte5[] = e(ai);
+ abyte5 = e(ai)
+ # ai = null;
+ ai = nil
+ # byte abyte6[] = new byte[byte1 + j4 + k3];
+ abyte6 = "\0"*(byte1 + j4 + k3)
+ # System.arraycopy(abyte4, 0, abyte6, 0, byte1);
+ abyte6[0, byte1] = abyte4[0, byte1]
+ # System.arraycopy(abyte2, 0, abyte6, byte1, k3);
+ abyte6[byte1, k3] = abyte2[0, k3]
+ # System.arraycopy(abyte5, 0, abyte6, byte1 + k3, j4);
+ abyte6[byte1+k3, j4] = abyte5[0, j4]
+ # byte abyte7[] = new byte[l2 + j3];
+ abyte7 = "\0"*(l2 + j3)
+ # System.arraycopy(abyte3, 0, abyte7, 0, l2);
+ abyte7[0, l2] = abyte3[0, l2]
+ # System.arraycopy(abyte0, 0, abyte7, l2, j3);
+ abyte7[l2, j3] = abyte0[0, j3]
+ # byte abyte8[] = i(null, abyte7, abyte6);
+ abyte8 = i(nil, abyte7, abyte6)
+ # if (abyte8 == null) {
+ # return "ZG_ENCRYPT_FAILED_MISC";
+ # }
+ if (abyte8 == nil)
+ return "ZG_ENCRYPT_FAILED_MISC"
+ # else {
+ # byte abyte9[] = new byte[abyte8.length + l2];
+ # System.arraycopy(abyte8, 0, abyte9, 0, abyte8.length);
+ # System.arraycopy(abyte3, 0, abyte9, abyte8.length, l2);
+ # String s3 = z(abyte9);
+ # return "ZG" + s3;
+ # }
+ else
+ abyte9 = "\0"*(abyte8.length + l2)
+ abyte9[0, abyte8.length] = abyte8[0, abyte8.length]
+ abyte9[abyte8.length, l2] = abyte3[0, l2]
+ s3 = z(abyte9)
+ return "ZG" + s3
+ end
+ # }
+ end
+
+ # private static void t(byte abyte0[], int ai[]) {
+ def t(abyte0, ai)
+ # int i1 = 0;
+ i1 = 0
+ # ai[0] = (abyte0[i1] & 0xff) << 24;
+ ai[0] = ((abyte0[i1] & 0xff) << 24) & 0xffffffff
+ # i1++;
+ i1 += 1
+ # ai[0] |= (abyte0[i1] & 0xff) << 16;
+ ai[0] |= ((abyte0[i1] & 0xff) << 16) & 0xffffffff
+ # i1++;
+ i1 += 1
+ # ai[0] |= (abyte0[i1] & 0xff) << 8;
+ ai[0] |= ((abyte0[i1] & 0xff) << 8) & 0xffffffff
+ # i1++;
+ i1 += 1
+ # ai[0] |= abyte0[i1] & 0xff;
+ ai[0] |= abyte0[i1] & 0xff
+ # i1++;
+ i1 += 1
+ # ai[1] = (abyte0[i1] & 0xff) << 24;
+ ai[1] = ((abyte0[i1] & 0xff) << 24) & 0xffffffff
+ # i1++;
+ i1 += 1
+ # ai[1] |= (abyte0[i1] & 0xff) << 16;
+ ai[1] |= ((abyte0[i1] & 0xff) << 16) & 0xffffffff
+ # i1++;
+ i1 += 1
+ # ai[1] |= (abyte0[i1] & 0xff) << 8;
+ ai[1] |= ((abyte0[i1] & 0xff) << 8) & 0xffffffff
+ # i1++;
+ i1 += 1
+ # ai[1] |= abyte0[i1] & 0xff;
+ ai[1] |= abyte0[i1] & 0xff
+ # }
+ end
+
+ # private static int u(int ai[], int ai1[]) {
+ def u(ai, ai1)
+ # boolean flag = false;
+ flag = false
+ # boolean flag1 = false;
+ flag1 = false
+ # int ai2[] = new int[80];
+ ai2 = [nil]*80
+ # int l1 = 0;
+ l1 = 0
+ # int ai3[] = new int[5];
+ ai3 = [nil]*5
+ # int ai4[] = new int[6];
+ ai4 = [nil]*6
+ # int ai5[] = new int[5];
+ ai5 = [nil]*5
+ # ai3[0] = 0x67452301;
+ # ai3[1] = 0xefcdab89;
+ # ai3[2] = 0x98badcfe;
+ # ai3[3] = 0x10325476;
+ # ai3[4] = 0xc3d2e1f0;
+ ai3[0] = 0x67452301
+ ai3[1] = 0xefcdab89
+ ai3[2] = 0x98badcfe
+ ai3[3] = 0x10325476
+ ai3[4] = 0xc3d2e1f0
+ # if (ai1 != null) {
+ if (ai1 != nil)
+ # if (ai != null) {
+ # System.arraycopy(ai, 0, ai4, 0, 5);
+ # }
+ if (ai != nil)
+ ai4[0, 5] = ai[0, 5]
+ end
+ # byte byte0 = 80;
+ byte0 = 80
+ # int i1;
+ # for (i1 = 0; i1 < 16; i1++) {
+ # ai2[i1] = ai1[i1];
+ #
+ # }
+ for i1 in 0...16
+ ai2[i1] = ai1[i1]
+ end
+ # for (; i1 < byte0; i1++) {
+ # ai2[i1] = ai2[i1 - 3] ^ ai2[i1 - 8] ^ ai2[i1 - 14] ^ ai2[i1 - 16];
+ #
+ # }
+ while (i1 < byte0)
+ ai2[i1] = ai2[i1 - 3] ^ ai2[i1 - 8] ^ ai2[i1 - 14] ^ ai2[i1 - 16]
+ i1 += 1
+ end
+ # for (int j1 = 0; j1 < 80; j1++) {
+ for j1 in 0...80
+ # if (j1 != 0) {
+ # System.arraycopy(ai4, 0, ai5, 0, 5);
+ # ai4[0] = ai5[4];
+ # ai4[1] = ai5[0];
+ # ai4[2] = ai5[1];
+ # ai4[3] = ai5[2];
+ # ai4[4] = ai5[3];
+ # }
+ if (j1 != 0)
+ ai5[0, 5] = ai4[0, 5]
+ ai4[0] = ai5[4];
+ ai4[1] = ai5[0];
+ ai4[2] = ai5[1];
+ ai4[3] = ai5[2];
+ ai4[4] = ai5[3];
+ end
+ # ai4[5] = ai2[j1];
+ ai4[5] = ai2[j1]
+ # if (j1 < 20) {
+ # H(ai4);
+ # }
+ if (j1 < 20)
+ h_(ai4)
+ # else
+ # if (j1 < 40) {
+ # I(ai4);
+ # }
+ elsif (j1 < 40)
+ i_(ai4)
+ # else
+ # if (j1 < 60) {
+ # c(ai4);
+ # }
+ elsif (j1 < 60)
+ c(ai4)
+ # else
+ # if (j1 < 80) {
+ # h(ai4);
+ # }
+ elsif (j1 < 80)
+ h(ai4)
+ end
+ # }
+ end
+ #
+ # ai3[0] = ai4[4];
+ # ai3[1] = ai4[0];
+ # ai3[2] = ai4[1];
+ # ai3[3] = ai4[2];
+ # ai3[4] = ai4[3];
+ ai3[0] = ai4[4];
+ ai3[1] = ai4[0];
+ ai3[2] = ai4[1];
+ ai3[3] = ai4[2];
+ ai3[4] = ai4[3];
+ # for (int k1 = 0; k1 < byte0; k1++) {
+ # ai2[k1] = 0;
+ #
+ # }
+ for k1 in 0...byte0
+ ai2[k1] = 0
+ end
+ # }
+ end
+ # if (ai != null) {
+ # ai[0] = ai3[0];
+ # ai[1] = ai3[1];
+ # ai[2] = ai3[2];
+ # ai[3] = ai3[3];
+ # ai[4] = ai3[4];
+ # }
+ if (ai != nil)
+ ai[0] = ai3[0];
+ ai[1] = ai3[1];
+ ai[2] = ai3[2];
+ ai[3] = ai3[3];
+ ai[4] = ai3[4];
+ end
+ # l1 = ai3[0] ^ ai3[1] ^ ai3[2] ^ ai3[3] ^ ai3[4];
+ l1 = ai3[0] ^ ai3[1] ^ ai3[2] ^ ai3[3] ^ ai3[4]
+ # return l1;
+ return l1
+ # }
+ end
+
+ # private static byte[] v(byte abyte0[], byte abyte1[], byte abyte2[]) {
+ # return g(y(abyte0, abyte1), abyte2);
+ # }
+ def v(abyte0, abyte1, abyte2)
+ return g(y(abyte0, abyte1), abyte2)
+ end
+
+ # private static String w(String s1, int i1, boolean flag) {
+ def w(s1, i1, flag)
+ # if (s1 == null) {
+ # return "";
+ # }
+ if (s1 == nil)
+ return ""
+ end
+ # int j1 = s1.length();
+ # TODO: should String be converted to Ruby Unicode chars string?
+ j1 = s1.length
+ # int k1 = s1.indexOf('\0');
+ k1 = s1.index("\0")
+ # if (k1 > -1) {
+ # j1 = k1;
+ # }
+ if (k1 > -1)
+ j1 = k1
+ end
+ # int l1;
+ # if (j1 > i1 && i1 > 0) {
+ # l1 = i1;
+ # }
+ if (j1 > i1 && i1 > 0)
+ l1 = i1
+ # else {
+ # l1 = j1;
+ # }
+ else
+ l1 = j1
+ end
+ # if (flag) {
+ # return new String(s1.substring(0, l1).toUpperCase(Locale.US));
+ # }
+ if (flag)
+ # TODO: should we do Unicode upcase?
+ return s1[0, l1].upcase
+ # else {
+ # return new String(s1.substring(0, l1));
+ # }
+ else
+ return s1[0, l1]
+ end
+ # }
+ end
+
+ # private static void x(int ai[], byte abyte0[]) {
+ def x(ai, abyte0)
+ # int i1 = 0;
+ i1 = 0
+ # abyte0[i1] = (byte) (ai[0] >> 24 & 0xff);
+ abyte0[i1] = (ai[0] >> 24 & 0xff)
+ # i1++;
+ i1 += 1
+ # abyte0[i1] = (byte) (ai[0] >> 16 & 0xff);
+ abyte0[i1] = (ai[0] >> 16 & 0xff)
+ # i1++;
+ i1 += 1
+ # abyte0[i1] = (byte) (ai[0] >> 8 & 0xff);
+ abyte0[i1] = (ai[0] >> 8 & 0xff)
+ # i1++;
+ i1 += 1
+ # abyte0[i1] = (byte) (ai[0] & 0xff);
+ abyte0[i1] = (ai[0] & 0xff)
+ # i1++;
+ i1 += 1
+ # abyte0[i1] = (byte) (ai[1] >> 24 & 0xff);
+ abyte0[i1] = (ai[1] >> 24 & 0xff)
+ # i1++;
+ i1 += 1
+ # abyte0[i1] = (byte) (ai[1] >> 16 & 0xff);
+ abyte0[i1] = (ai[1] >> 16 & 0xff)
+ # i1++;
+ i1 += 1
+ # abyte0[i1] = (byte) (ai[1] >> 8 & 0xff);
+ abyte0[i1] = (ai[1] >> 8 & 0xff)
+ # i1++;
+ i1 += 1
+ # abyte0[i1] = (byte) (ai[1] & 0xff);
+ abyte0[i1] = (ai[1] & 0xff)
+ # }
+ end
+
+ # static String oldCheck(String s1, String s2, boolean flag) {
+ def old_check(s1, s2, flag)
+ # byte abyte0[] = A(s1.toCharArray());
+ abyte0 = a_(s1.dup)
+ # byte abyte1[] = p(s2);
+ abyte1 = p(s2)
+ # byte abyte2[] = k(abyte0, abyte1, abyte1.length);
+ abyte2 = k(abyte0, abyte1, abyte1.length)
+ # char ac[] = m(abyte2);
+ ac = m(abyte2)
+ # if (ac != null) {
+ # String s3 = new String(ac);
+ # return w(s3, 0, flag);
+ # }
+ if (ac != nil)
+ s3 = ac.to_s
+ # else {
+ # return null;
+ # }
+ else
+ return nil
+ end
+ # }
+ end
+
+ # private static byte[] y(byte abyte0[], byte abyte1[]) {
+ def y(abyte0, abyte1)
+ # puts "<br/>DEBUG y: abyte0=#{abyte0.nil? ? "nil" : abyte0.unpack("H*")[0]}"
+ # puts "<br/>DEBUG y: abyte1=#{abyte1.nil? ? "nil" : abyte1.unpack("H*")[0]}"
+ # byte abyte2[] = new byte[32];
+ abyte2 = "\0"*32
+ # MessageDigest messagedigest;
+ # try {
+ # messagedigest = MessageDigest.getInstance("SHA");
+ # }
+ # catch (NoSuchAlgorithmException _ex) {
+ # return null;
+ # }
+ messagedigest = Digest::SHA1.new
+ # messagedigest.reset();
+ messagedigest.reset
+ # byte byte0 = 20;
+ byte0 = 20
+ # if (abyte0 != null && abyte0.length > 0) {
+ # messagedigest.update(abyte0);
+ # }
+ if (abyte0 != nil && abyte0.length > 0)
+ messagedigest.update(abyte0)
+ end
+ # if (abyte1 != null && abyte1.length > 0) {
+ # messagedigest.update(abyte1);
+ # }
+ if (abyte1 != nil && abyte1.length > 0)
+ messagedigest.update(abyte1)
+ end
+ # messagedigest.update( (byte) 1);
+ messagedigest.update(1.chr)
+ # byte abyte3[] = messagedigest.digest();
+ abyte3 = messagedigest.digest
+ # puts "<br/>DEBUG y: abyte3=#{abyte3.nil? ? "nil" : abyte3.unpack("H*")[0]}"
+ # System.arraycopy(abyte3, 0, abyte2, 0, byte0);
+ abyte2[0, byte0] = abyte3[0, byte0]
+ # messagedigest.reset();
+ messagedigest.reset()
+ # if (abyte0 != null && abyte0.length > 0) {
+ # messagedigest.update(abyte0);
+ # }
+ if (abyte0 != nil && abyte0.length > 0)
+ messagedigest.update(abyte0)
+ end
+ # if (abyte1 != null && abyte1.length > 0) {
+ # messagedigest.update(abyte1);
+ # }
+ if (abyte1 != nil && abyte1.length > 0)
+ messagedigest.update(abyte1)
+ end
+ # messagedigest.update( (byte) 2);
+ messagedigest.update( 2.chr )
+ # abyte3 = messagedigest.digest();
+ abyte3 = messagedigest.digest
+ # System.arraycopy(abyte3, 0, abyte2, byte0, 32 - byte0);
+ abyte2[byte0, 32 - byte0] = abyte3[0, 32 - byte0]
+ # return abyte2;
+ # puts "<br/>DEBUG y: abyte2=#{abyte2.unpack("H*")[0]}"
+ return abyte2
+ # }
+ end
+
+ # private static String z(byte abyte0[]) {
+ def z(abyte0)
+ # # if (abyte0 == null) {
+ # # return null;
+ # # }
+ # if (abyte0 == nil)
+ # return nil
+ # end
+ # # String s1 = "0123456789ABCDEF";
+ # s1 = "0123456789ABCDEF"
+ # # StringBuffer stringbuffer = new StringBuffer(abyte0.length * 2);
+ # stringbuffer = ""
+ # # int i1 = 0;
+ # i1 = 0
+ # # for (int j1 = abyte0.length; j1 > 0; ) {
+ # j1 = abyte0.length
+ # while (j1 > 0)
+ # # byte byte0 = abyte0[i1];
+ # byte0 = abyte0[i1]
+ # # stringbuffer.append(s1.charAt(byte0 >> 4 & 0xf));
+ # stringbuffer << s1[byte0 >> 4 & 0xf]
+ # # stringbuffer.append(s1.charAt(byte0 & 0xf));
+ # stringbuffer << s1[byte0 & 0xf]
+ # # j1--;
+ # j1 -= 1
+ # # i1++;
+ # i1 += 1
+ # # }
+ # end
+ # #
+ # # return stringbuffer.toString();
+ # return stringbuffer
+ # # }
+ abyte0.unpack("H*")[0].upcase
+ end
+
+ # private static byte[] A(char ac[]) {
+ def a_(ac)
+ # RSI: if we receive String then return the same value (as it should already be in UTF-8)
+ return ac if ac.is_a? String
+ # byte abyte0[] = new byte[ac.length * 3];
+ abyte0 = "\0"*(ac.length * 3)
+ # int i1 = 0;
+ i1 = 0
+ # boolean flag = false;
+ flag = false
+ # for (int j1 = 0; j1 < ac.length; j1++) {
+ for j1 in 0...ac.length
+ # char c1 = ac[j1];
+ c1 = ac[j1]
+ # if (c1 >= 0 && c1 <= '\177') {
+ # abyte0[i1++] = (byte) (c1 & 0x7f);
+ # }
+ if (c1 >= 0 && c1 <= 0177)
+ abyte0[i1] = (c1 & 0x7f)
+ i1 += 1
+ # else
+ # if (c1 >= '\200' && c1 <= '\u07FF') {
+ # abyte0[i1++] = (byte) ( (c1 & 0x7c0) >> 6 | 0xc0);
+ # abyte0[i1++] = (byte) (c1 & 0x3f | 0x80);
+ # }
+ elsif (c1 >= 0200 && c1 <= 0x07FF)
+ abyte0[i1] = ( (c1 & 0x7c0) >> 6 | 0xc0)
+ i1 += 1
+ abyte0[i1] = (c1 & 0x3f | 0x80)
+ i1 += 1
+ # else
+ # if (c1 >= '\u0800' && c1 <= '\uFFFF') {
+ # abyte0[i1++] = (byte) ( (c1 & 0xf000) >> 12 | 0xe0);
+ # abyte0[i1++] = (byte) ( (c1 & 0xfc0) >> 6 | 0x80);
+ # abyte0[i1++] = (byte) (c1 & 0x3f | 0x80);
+ # }
+ elsif (c1 >= 0x0800 && c1 <= 0xFFFF)
+ abyte0[i1] = ( (c1 & 0xf000) >> 12 | 0xe0)
+ i1 += 1
+ abyte0[i1] = ( (c1 & 0xfc0) >> 6 | 0x80)
+ i1 += 1
+ abyte0[i1] = (c1 & 0x3f | 0x80)
+ i1 += 1
+ end
+ # }
+ end
+ #
+ # byte abyte1[] = new byte[i1];
+ abyte1 = "\0"*i1
+ # System.arraycopy(abyte0, 0, abyte1, 0, i1);
+ abyte1[0, i1] = abyte0[0, i1]
+ # return abyte1;
+ abyte1
+ # }
+ end
+
+ # private static void B(byte abyte0[], byte abyte1[], byte abyte2[], int i1) {
+ def b_(abyte0, abyte1, abyte2, i1)
+ # if (abyte0 == null) {
+ if (abyte0 == nil)
+ # if (i1 > 0 && abyte1 != null && abyte2 != null) {
+ if (i1 > 0 && abyte1 != nil && abyte2 != nil)
+ # for (int j1 = 0; j1 < i1; j1++) {
+ # abyte2[j1] = abyte1[j1];
+ #
+ # }
+ for j1 in 0...i1
+ abyte2[j1] = abyte1[j1]
+ end
+ # return;
+ return
+ # }
+ end
+ # }
+ # else {
+ # if (abyte2 == null) {
+ else
+ if (abyte2 == nil)
+ # for (int k1 = 0; k1 < 256; k1++) {
+ # abyte0[k1] = (byte) k1;
+ #
+ # }
+ for k1 in 0...256
+ abyte0[k1] = k1
+ end
+ # if (abyte1 != null && i1 > 0) {
+ if (abyte1 != nil && i1 > 0)
+ # int j2 = 0;
+ j2 = 0
+ # int l2 = 0;
+ l2 = 0
+ # for (int l1 = 0; l1 < 256; l1++) {
+ # int j3 = (new Byte(abyte0[l1])).intValue() & 0xff;
+ # j2 = j2 + j3 + ( (new Byte(abyte1[l2])).intValue() & 0xff) & 0xff;
+ # abyte0[l1] = abyte0[j2];
+ # abyte0[j2] = (new Integer(j3 & 0xff)).byteValue();
+ # l2 = (l2 + 1) % i1;
+ # }
+ for l1 in 0...256
+ j3 = abyte0[l1] & 0xff
+ j2 = j2 + j3 + ( abyte1[l2] & 0xff) & 0xff
+ abyte0[l1] = abyte0[j2]
+ abyte0[j2] = j3 & 0xff
+ l2 = (l2 + 1) % i1
+ end
+ #
+ # }
+ end
+ # abyte0[256] = 0;
+ abyte0[256] = 0
+ # abyte0[257] = 0;
+ abyte0[257] = 0
+ # return;
+ return
+ # }
+ end
+ # int i2 = (new Byte(abyte0[256])).intValue() & 0xff;
+ i2 = abyte0[256] & 0xff
+ # int k2 = (new Byte(abyte0[257])).intValue() & 0xff;
+ k2 = abyte0[257] & 0xff
+ # for (int i3 = 0; i3 < i1; i3++) {
+ for i3 in 0...i1
+ # i2 = i2 + 1 & 0xff;
+ i2 = i2 + 1 & 0xff
+ # int k3 = (new Byte(abyte0[i2])).intValue() & 0xff;
+ k3 = abyte0[i2] & 0xff
+ # k2 = k2 + k3 & 0xff;
+ k2 = k2 + k3 & 0xff
+ # abyte0[i2] = abyte0[k2];
+ abyte0[i2] = abyte0[k2]
+ # abyte0[k2] = (new Integer(k3 & 0xff)).byteValue();
+ abyte0[k2] = k3 & 0xff
+ # k3 += (new Byte(abyte0[i2])).intValue() & 0xff;
+ k3 += abyte0[i2] & 0xff
+ # abyte2[i3] = (byte) (abyte1[i3] ^ abyte0[k3 & 0xff]);
+ abyte2[i3] = (abyte1[i3] ^ abyte0[k3 & 0xff])
+ # new String("");
+ ""
+ # }
+ end
+ #
+ # abyte0[256] = (byte) (i2 & 0xff);
+ abyte0[256] = (i2 & 0xff)
+ # abyte0[257] = (byte) (k2 & 0xff);
+ abyte0[257] = (k2 & 0xff)
+ # }
+ end
+ # }
+ end
+
+ # static boolean check(String s1, String s2, boolean flag) {
+ def check(s1, s2, flag)
+ return true if decrypt(s1, s2, flag)
+ false
+ end
+
+ def decrypt(s1, s2, flag)
+ # String cid;
+ # if (s2 != null && s2.length() > 0) {
+ if (s2 != nil && s2.length() > 0)
+ # if (s2.substring(0, 2).equals("ZG")) {
+ # cid = newCheck(s1, s2, flag);
+ # }
+ if (s2[0, 2] == "ZG")
+ cid = new_check(s1, s2, flag)
+ # else {
+ # cid= oldCheck(s1, s2, flag);
+ # }
+ else
+ cid = old_check(s1, s2, flag)
+ end
+ # }
+ # else {
+ # return false;
+ # }
+ else
+ return false
+ end
+ # if (cid==null) {
+ # return false;
+ # } else {
+ # return true;
+ # }
+ return cid
+ # }
+ end
+
+ # private static int[] C(int ai[]) {
+ def c_(ai)
+ # int ai1[] = new int[32];
+ ai1 = [nil]*32
+ # int ai2[] = ai;
+ ai2 = ai
+ # int i1 = 0;
+ i1 = 0
+ # boolean flag = false;
+ flag = false
+ # int k1 = 0;
+ k1 = 0
+ # int l1 = 0;
+ l1 = 0
+ # while (i1 < 16) {
+ while (i1 < 16)
+ # int j1 = k1++;
+ j1 = k1
+ k1 += 1
+ # ai1[l1] = (ai2[j1] & 0xfc0000) << 6;
+ ai1[l1] = (ai2[j1] & 0xfc0000) << 6
+ # ai1[l1] |= (ai2[j1] & 0xfc0) << 10;
+ ai1[l1] |= (ai2[j1] & 0xfc0) << 10
+ # ai1[l1] |= (ai[k1] & 0xfc0000) >> 10;
+ ai1[l1] |= (ai[k1] & 0xfc0000) >> 10
+ # ai1[l1] |= (ai[k1] & 0xfc0) >> 6;
+ ai1[l1] |= (ai[k1] & 0xfc0) >> 6
+ # l1++;
+ l1 += 1
+ # ai1[l1] = (ai2[j1] & 0x3f000) << 12;
+ ai1[l1] = (ai2[j1] & 0x3f000) << 12
+ # ai1[l1] |= (ai2[j1] & 0x3f) << 16;
+ ai1[l1] |= (ai2[j1] & 0x3f) << 16
+ # ai1[l1] |= (ai[k1] & 0x3f000) >> 4;
+ ai1[l1] |= (ai[k1] & 0x3f000) >> 4
+ # ai1[l1] |= ai[k1] & 0x3f;
+ ai1[l1] |= ai[k1] & 0x3f
+ # l1++;
+ l1 += 1
+ # i1++;
+ i1 += 1
+ # k1++;
+ k1 += 1
+ # }
+ end
+ # return ai1;
+ return ai1
+ # }
+ end
+
+ # private static void D(byte abyte0[], byte abyte1[], byte abyte2[], int i1) {
+ def d_(abyte0, abyte1, abyte2, i1)
+ # for (int j1 = 0; j1 < 8; j1++) {
+ # abyte2[j1 + i1] = (byte) (abyte0[j1] ^ abyte1[j1]);
+ #
+ # }
+ for j1 in 0...8
+ abyte2[j1 + i1] = (abyte0[j1] ^ abyte1[j1])
+ end
+ # }
+ end
+
+ # private static void E(String s1) {
+ # }
+ def e_(s1)
+ end
+
+ # private static void F(int ai[], int ai1[]) {
+ def f_(ai, ai1)
+ # int j2 = 0;
+ j2 = 0
+ # int l1 = ai[0];
+ l1 = ai[0]
+ # int k1 = ai[1];
+ k1 = ai[1]
+ # int j1 = (l1 >>> 4 ^ k1) & 0xf0f0f0f;
+ # TODO: check that it is safe to replace >>> with >>
+ j1 = (l1 >> 4 ^ k1) & 0xf0f0f0f
+ # k1 ^= j1;
+ k1 ^= j1
+ # l1 ^= j1 << 4;
+ l1 ^= (j1 << 4) & 0xffffffff
+ # j1 = (l1 >>> 16 ^ k1) & 0xffff;
+ # TODO: check that it is safe to replace >>> with >>
+ j1 = (l1 >> 16 ^ k1) & 0xffff
+ # k1 ^= j1;
+ k1 ^= j1
+ # l1 ^= j1 << 16;
+ l1 ^= (j1 << 16) & 0xffffffff
+ # j1 = (k1 >>> 2 ^ l1) & 0x33333333;
+ # TODO: check that it is safe to replace >>> with >>
+ j1 = (k1 >> 2 ^ l1) & 0x33333333
+ # l1 ^= j1;
+ l1 ^= j1
+ # k1 ^= j1 << 2;
+ k1 ^= (j1 << 2) & 0xffffffff
+ # j1 = (k1 >>> 8 ^ l1) & 0xff00ff;
+ j1 = (k1 >> 8 ^ l1) & 0xff00ff
+ # l1 ^= j1;
+ l1 ^= j1
+ # k1 ^= j1 << 8;
+ k1 ^= (j1 << 8) & 0xffffffff
+ # k1 = (k1 << 1 | k1 >>> 31 & 1) & -1;
+ # TODO: check that it is safe to replace >>> with >>
+ k1 = (k1 << 1 | k1 >> 31 & 1) & 0xffffffff
+ # j1 = (l1 ^ k1) & 0xaaaaaaaa;
+ j1 = (l1 ^ k1) & 0xaaaaaaaa
+ # l1 ^= j1;
+ l1 ^= j1
+ # k1 ^= j1;
+ k1 ^= j1
+ # l1 = (l1 << 1 | l1 >>> 31 & 1) & -1;
+ # TODO: check that it is safe to replace >>> with >>
+ l1 = (l1 << 1 | l1 >> 31 & 1) & 0xffffffff
+ # for (int i2 = 0; i2 < 8; i2++) {
+ for i2 in 0...8
+ # j1 = k1 << 28 | k1 >>> 4;
+ # TODO: check that it is safe to replace >>> with >>
+ j1 = (k1 << 28 | k1 >> 4) & 0xffffffff
+ # long l2 = 0L;
+ # TODO: check if long integeres are processed automatically
+ l2 = 0
+ # l2 = ai1[j2];
+ l2 = ai1[j2]
+ # j1 ^= ai1[j2];
+ j1 ^= ai1[j2]
+ # j2++;
+ j2 += 1
+ # int i1 = bj[j1 & 0x3f];
+ i1 = Bj[j1 & 0x3f]
+ # i1 |= L[j1 >>> 8 & 0x3f];
+ # TODO: check if long integeres are processed automatically
+ i1 |= L[j1 >> 8 & 0x3f]
+ # i1 |= P[j1 >>> 16 & 0x3f];
+ i1 |= P[j1 >> 16 & 0x3f]
+ # i1 |= T[j1 >>> 24 & 0x3f];
+ i1 |= T[j1 >> 24 & 0x3f]
+ # j1 = k1 ^ ai1[j2];
+ j1 = k1 ^ ai1[j2]
+ # j2++;
+ j2 += 1
+ # i1 |= bg[j1 & 0x3f];
+ i1 |= Bg[j1 & 0x3f]
+ # i1 |= bm[j1 >>> 8 & 0x3f];
+ i1 |= Bm[j1 >> 8 & 0x3f]
+ # i1 |= N[j1 >>> 16 & 0x3f];
+ i1 |= N[j1 >> 16 & 0x3f]
+ # i1 |= R[j1 >>> 24 & 0x3f];
+ i1 |= R[j1 >> 24 & 0x3f]
+ # l1 ^= i1;
+ l1 ^= i1
+ # j1 = l1 << 28 | l1 >>> 4;
+ j1 = (l1 << 28 | l1 >> 4) & 0xffffffff
+ # j1 ^= ai1[j2];
+ j1 ^= ai1[j2]
+ # j2++;
+ j2 += 1
+ # i1 = bj[j1 & 0x3f];
+ i1 = Bj[j1 & 0x3f]
+ # i1 |= L[j1 >>> 8 & 0x3f];
+ i1 |= L[j1 >> 8 & 0x3f]
+ # i1 |= P[j1 >>> 16 & 0x3f];
+ i1 |= P[j1 >> 16 & 0x3f]
+ # i1 |= T[j1 >>> 24 & 0x3f];
+ i1 |= T[j1 >> 24 & 0x3f]
+ # j1 = l1 ^ ai1[j2];
+ j1 = l1 ^ ai1[j2]
+ # j2++;
+ j2 += 1
+ # i1 |= bg[j1 & 0x3f];
+ i1 |= Bg[j1 & 0x3f]
+ # i1 |= bm[j1 >>> 8 & 0x3f];
+ i1 |= Bm[j1 >> 8 & 0x3f]
+ # i1 |= N[j1 >>> 16 & 0x3f];
+ i1 |= N[j1 >> 16 & 0x3f]
+ # i1 |= R[j1 >>> 24 & 0x3f];
+ i1 |= R[j1 >> 24 & 0x3f]
+ # k1 ^= i1;
+ k1 ^= i1
+ # }
+ end
+ #
+ # k1 = k1 << 31 | k1 >>> 1;
+ k1 = (k1 << 31 | k1 >> 1) & 0xffffffff
+ # j1 = (l1 ^ k1) & 0xaaaaaaaa;
+ j1 = (l1 ^ k1) & 0xaaaaaaaa
+ # l1 ^= j1;
+ l1 ^= j1
+ # k1 ^= j1;
+ k1 ^= j1
+ # l1 = l1 << 31 | l1 >>> 1;
+ l1 = l1 << 31 | l1 >> 1
+ # j1 = (l1 >>> 8 ^ k1) & 0xff00ff;
+ j1 = (l1 >> 8 ^ k1) & 0xff00ff
+ # k1 ^= j1;
+ k1 ^= j1
+ # l1 ^= j1 << 8;
+ l1 ^= (j1 << 8) & 0xffffffff
+ # j1 = (l1 >>> 2 ^ k1) & 0x33333333;
+ j1 = (l1 >> 2 ^ k1) & 0x33333333
+ # k1 ^= j1;
+ k1 ^= j1
+ # l1 ^= j1 << 2;
+ l1 ^= (j1 << 2) & 0xffffffff
+ # j1 = (k1 >>> 16 ^ l1) & 0xffff;
+ j1 = (k1 >> 16 ^ l1) & 0xffff
+ # l1 ^= j1;
+ l1 ^= j1
+ # k1 ^= j1 << 16;
+ k1 ^= (j1 << 16) & 0xffffffff
+ # j1 = (k1 >>> 4 ^ l1) & 0xf0f0f0f;
+ j1 = (k1 >> 4 ^ l1) & 0xf0f0f0f
+ # l1 ^= j1;
+ l1 ^= j1
+ # k1 ^= j1 << 4;
+ k1 ^= (j1 << 4) & 0xffffffff
+ # ai[0] = k1;
+ ai[0] = k1
+ # ai[1] = l1;
+ ai[1] = l1
+ # }
+ end
+
+ # private static byte[] G(byte abyte0[], byte abyte1[]) {
+ def g_(abyte0, abyte1)
+ # if (abyte0.length < 32) {
+ # return null;
+ # }
+ if (abyte0.length < 32)
+ return nil
+ end
+ # byte abyte3[] = new byte[8];
+ abyte3 = "\0"*8
+ # byte abyte4[] = new byte[8];
+ abyte4 = "\0"*8
+ # byte abyte5[] = new byte[8];
+ abyte5 = "\0"*8
+ # byte abyte2[] = new byte[8];
+ abyte2 = "\0"*8
+ # System.arraycopy(abyte0, 0, abyte3, 0, 8);
+ abyte3[0, 8] = abyte0[0, 8]
+ # System.arraycopy(abyte0, 8, abyte4, 0, 8);
+ abyte4[0, 8] = abyte0[8, 8]
+ # System.arraycopy(abyte0, 16, abyte5, 0, 8);
+ abyte5[0, 8] = abyte0[16, 8]
+ # System.arraycopy(abyte0, 24, abyte2, 0, 8);
+ abyte2[0, 8] = abyte0[24, 0]
+ # int ai[] = l(abyte3, true);
+ ai = l(abyte3, true)
+ # int ai1[] = l(abyte4, false);
+ ai1 = l(abyte4, false)
+ # int ai2[] = l(abyte5, true);
+ ai2 = l(abyte5, true)
+ # int i1 = abyte1.length % 8;
+ i1 = abyte1.length % 8
+ # byte byte0 = (byte) (8 - i1);
+ byte0 = (8 - i1)
+ # byte abyte6[] = new byte[abyte1.length + byte0];
+ abyte6 = "\0"*(abyte1.length + byte0)
+ # int j1 = abyte6.length / 8 - 1;
+ j1 = abyte6.length / 8 - 1
+ # int k1 = 8 * j1;
+ k1 = 8 * j1
+ # byte abyte7[] = new byte[8];
+ abyte7 = "\0"*8
+ # System.arraycopy(abyte1, k1, abyte7, 0, i1);
+ abyte7[0, i1] = abyte1[k1, i1]
+ # for (int l1 = i1; l1 < 8; l1++) {
+ # abyte7[l1] = byte0;
+ #
+ # }
+ for l1 in i1...8
+ abyte7[l1] = byte0
+ end
+ # int i2 = 0;
+ i2 = 0
+ # for (int j2 = 0; i2 < j1; j2 += 8) {
+ # q(abyte1, j2, abyte6, j2, ai, ai1, ai2, abyte2, true);
+ # i2++;
+ # }
+ j2 = 0
+ while (i2 < j1)
+ q(abyte1, j2, abyte6, j2, ai, ai1, ai2, abyte2, true)
+ i2 += 1
+ j2 += 8
+ end
+ #
+ # q(abyte7, 0, abyte6, k1, ai, ai1, ai2, abyte2, true);
+ q(abyte7, 0, abyte6, k1, ai, ai1, ai2, abyte2, true)
+ # return abyte6;
+ return abyte6
+ # }
+ end
+
+ # private static void H(int ai[]) {
+ # ai[4] = j(ai[0], 5) + r(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0x5a827999;
+ # ai[2] = j(ai[1], 30);
+ # }
+ def h_(ai)
+ ai[4] = j(ai[0], 5) + r(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0x5a827999
+ ai[2] = j(ai[1], 30)
+ end
+
+ # private static void I(int ai[]) {
+ # ai[4] = j(ai[0], 5) + n(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0x6ed9eba1;
+ # ai[2] = j(ai[1], 30);
+ # }
+ def i_(ai)
+ ai[4] = j(ai[0], 5) + n(ai[1], ai[2], ai[3]) + ai[4] + ai[5] + 0x6ed9eba1
+ ai[2] = j(ai[1], 30)
+ end
+
+ J = 2
+ K = 4
+
+ L = [
+ 256, 0x2080100, 0x2080000, 0x42000100, 0x80000, 256, 0x40000000,
+ 0x2080000, 0x40080100, 0x80000,
+ 0x2000100, 0x40080100, 0x42000100, 0x42080000, 0x80100, 0x40000000,
+ 0x2000000, 0x40080000, 0x40080000, 0,
+ 0x40000100, 0x42080100, 0x42080100, 0x2000100, 0x42080000, 0x40000100, 0,
+ 0x42000000, 0x2080100, 0x2000000,
+ 0x42000000, 0x80100, 0x80000, 0x42000100, 256, 0x2000000, 0x40000000,
+ 0x2080000, 0x42000100, 0x40080100,
+ 0x2000100, 0x40000000, 0x42080000, 0x2080100, 0x40080100, 256, 0x2000000,
+ 0x42080000, 0x42080100, 0x80100,
+ 0x42000000, 0x42080100, 0x2080000, 0, 0x40080000, 0x42000000, 0x80100,
+ 0x2000100, 0x40000100, 0x80000,
+ 0, 0x40080000, 0x2080100, 0x40000100
+ ]
+ M = 2
+ N = [
+ 0x802001, 8321, 8321, 128, 0x802080, 0x800081, 0x800001, 8193, 0,
+ 0x802000,
+ 0x802000, 0x802081, 129, 0, 0x800080, 0x800001, 1, 8192, 0x800000,
+ 0x802001,
+ 128, 0x800000, 8193, 8320, 0x800081, 1, 8320, 0x800080, 8192, 0x802080,
+ 0x802081, 129, 0x800080, 0x800001, 0x802000, 0x802081, 129, 0, 0,
+ 0x802000,
+ 8320, 0x800080, 0x800081, 1, 0x802001, 8321, 8321, 128, 0x802081, 129,
+ 1, 8192, 0x800001, 8193, 0x802080, 0x800081, 8193, 8320, 0x800000,
+ 0x802001,
+ 128, 0x800000, 8192, 0x802080
+ ]
+ O = 1
+ P = [
+ 520, 0x8020200, 0, 0x8020008, 0x8000200, 0, 0x20208, 0x8000200, 0x20008,
+ 0x8000008,
+ 0x8000008, 0x20000, 0x8020208, 0x20008, 0x8020000, 520, 0x8000000, 8,
+ 0x8020200, 512,
+ 0x20200, 0x8020000, 0x8020008, 0x20208, 0x8000208, 0x20200, 0x20000,
+ 0x8000208, 8, 0x8020208,
+ 512, 0x8000000, 0x8020200, 0x8000000, 0x20008, 520, 0x20000, 0x8020200,
+ 0x8000200, 0,
+ 512, 0x20008, 0x8020208, 0x8000200, 0x8000008, 512, 0, 0x8020008,
+ 0x8000208, 0x20000,
+ 0x8000000, 0x8020208, 8, 0x20208, 0x20200, 0x8000008, 0x8020000,
+ 0x8000208, 520, 0x8020000,
+ 0x20208, 8, 0x8020008, 0x20200
+ ]
+ Q = 0x8f1bbcdc
+ R = [
+ 0x80108020, 0x80008000, 32768, 0x108020, 0x100000, 32, 0x80100020,
+ 0x80008020, 0x80000020, 0x80108020,
+ 0x80108000, 0x80000000, 0x80008000, 0x100000, 32, 0x80100020, 0x108000,
+ 0x100020, 0x80008020, 0,
+ 0x80000000, 32768, 0x108020, 0x80100000, 0x100020, 0x80000020, 0,
+ 0x108000, 32800, 0x80108000,
+ 0x80100000, 32800, 0, 0x108020, 0x80100020, 0x100000, 0x80008020,
+ 0x80100000, 0x80108000, 32768,
+ 0x80100000, 0x80008000, 32, 0x80108020, 0x108020, 32, 32768, 0x80000000,
+ 32800, 0x80108000,
+ 0x100000, 0x80000020, 0x100020, 0x80008020, 0x80000020, 0x100020,
+ 0x108000, 0, 0x80008000, 32800,
+ 0x80000000, 0x80100020, 0x80108020, 0x108000
+ ]
+ S = [
+ 13, 16, 10, 23, 0, 4, 2, 27, 14, 5,
+ 20, 9, 22, 18, 11, 3, 25, 7, 15, 6,
+ 26, 19, 12, 1, 40, 51, 30, 36, 46, 54,
+ 29, 39, 50, 44, 32, 47, 43, 48, 38, 55,
+ 33, 52, 45, 41, 49, 35, 28, 31
+ ]
+ T = [
+ 0x1010400, 0, 0x10000, 0x1010404, 0x1010004, 0x10404, 4, 0x10000, 1024,
+ 0x1010400,
+ 0x1010404, 1024, 0x1000404, 0x1010004, 0x1000000, 4, 1028, 0x1000400,
+ 0x1000400, 0x10400,
+ 0x10400, 0x1010000, 0x1010000, 0x1000404, 0x10004, 0x1000004, 0x1000004,
+ 0x10004, 0, 1028,