summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Bogk <andreas@pt141.(none)>2009-01-23 20:52:29 +0100
committerAndreas Bogk <andreas@pt141.(none)>2009-01-23 20:52:29 +0100
commit3293cd52b23a1f0736aff7b0a8c9078dc976c04f (patch)
tree40284e3ef0a493d3c79fa24c42252dad6fdaf7e9
parentc7a1baf3228bae5176976b89a4b7347bba58950b (diff)
Make start value calculation more clear.
-rw-r--r--A5.1/C/calculate_chain.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/A5.1/C/calculate_chain.c b/A5.1/C/calculate_chain.c
index 5b6d18e..28aec0f 100644
--- a/A5.1/C/calculate_chain.c
+++ b/A5.1/C/calculate_chain.c
@@ -123,19 +123,37 @@ uint64 calculate_chain (uint64 input, uint32 count) {
input = calculate_link(input, i);
}
return input;
-}
+}
+
+/* Linear congruential generator used to whiten start value.
+ * Numbers stolen from Lawrence Livermore National Laboratory RNG
+ * library: http://nuclear.llnl.gov/CNP/rng/rngman/node4.html
+ */
+uint64 start_value_from_index (uint64 count) {
+ return 2862933555777941757UL * (count + 1) + 3037000493L;
+}
+
+void usage (char* argv[]) {
+ printf("Usage: %s <startvalue>\n\nSpecify the start value as 16 hex digits, or chain number as 10 hex digits. Calculates one\nchain of the A5/1 rainbow table, and outputs the end value.\n", argv[0]);
+ exit(1);
+}
int main(int argc, char* argv[]) {
int i,j;
uint64 current;
- if (argc<2 || sscanf(argv[1], "%16lx", &current) != 1) {
- printf("Usage: %s <startvalue>\n\nSpecify the start value as 16 hex digits. Calculates one\nchain of the A5/1 rainbow table, and outputs the end value.\n", argv[0]);
- exit(1);
+ if (argc<2) {
+ usage(argv);
+ } else if (strlen(argv[1])==16 && sscanf(argv[1], "%16lx", &current) == 1) {
+ printf("Calculating chain from start value 0x%16.16lx\n", current);
+ current = calculate_chain(current, pow(2, 21));
+ } else if (sscanf(argv[1], "%16lx", &current) == 1) {
+ current = start_value_from_index(current);
+ printf("Calculating chain from start value 0x%16.16lx\n", current);
+ current = calculate_chain(current, pow(2, 21));
+ } else {
+ usage(argv);
}
-
- current = calculate_chain(current, pow(2, 21));
-
- printf("%16.16lx\n", current);
+ printf("End value: 0x%16.16lx\n", current);
return 0;
}
personal git repositories of Harald Welte. Your mileage may vary