项目作者: asnelt

项目描述 :
Android pseudo random number predictor
高级语言: Java
项目地址: git://github.com/asnelt/derandom.git
创建时间: 2015-03-12T23:52:40Z
项目社区:https://github.com/asnelt/derandom

开源协议:Apache License 2.0

下载


Derandom

Predicts pseudo random numbers based on a sequence of observed numbers.

Usage

Enter a sequence of numbers that you obtained from a pseudo random number
generator like, for instance, the Java standard pseudo random number
generator or the Mersenne Twister MT19937. The app will then try to
predict following numbers from the generator.

The app expects all numbers to be entered as integers or floating point
numbers between zero and one. Currently, floating point numbers are
supported for the Mersenne Twister only. Three input modes are
supported:

  1. Text field lets you enter the numbers directly on the device.
  2. File lets you choose a file with newline separated number strings.
  3. Socket opens a server socket on the device. You can then connect
    with a custom client by means of a client socket and send newline
    separated number strings to the server. After each number the server
    will send back the next newline separated predictions. Each block of
    predictions is separated by an additional newline.

To test the app, enter the following numbers in the Text field:

  1. 1412437139
  2. 1552322984
  3. 168467398
  4. 1111755060
  5. -928874005

These numbers were sampled from the Java linear congruential generator
Random.nextInt(). Thus, the app should detect LCG: Java after the
third number input, and numbers in the prediction history should appear
in green instead of red, indicating that those numbers were correctly
predicted.

The following Python program can be used to test socket input. The
program samples numbers from the standard Python pseudo random number
generator and sends them to a network socket:

  1. import random
  2. import socket
  3. HOST = "localhost" # Host of Android device
  4. PORT = 6869 # Default Derandom port
  5. with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
  6. s.connect((HOST, PORT))
  7. buffer = s.makefile() # Buffer for readline
  8. for _ in range(0, 700):
  9. # Sample bits from generator
  10. bits = random.getrandbits(32)
  11. # Send number string
  12. message = str(bits) + "\n"
  13. s.sendall(message.encode())
  14. # Read and print predictions
  15. for _ in range(0, 9): # 8 predictions and newline
  16. line = buffer.readline()
  17. print(line, end="")

Start the app on the Android device and set the input spinner from
Text field to Socket. Make sure that the device and the Derandom
socket port (default 6869) are reachable in your network. Then set
HOST in the Python program to the address of your Android device and
run the program. For each number that is sent by the Python program,
eight predictions are returned by Derandom and displayed by the Python
program. After the app has received 624 numbers the Python Mersenne
Twister should be detected and, in the app, numbers in the prediction
history should appear in green instead of red. You can also replace
random.getrandbits(32) with random.random() and send 1300 numbers
instead of 700 numbers to account for unobserved bits.

Building from source

Define SDK location with sdk.dir in the local.properties file or with
an ANDROID_HOME environment variable. Then type the following command
to build in release mode:

  1. ./gradlew assembleRelease

License

  1. Copyright (C) 2015-2024 Arno Onken
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.