Creation

March 3, 2009

14 11 78 17 27 12 83 37 0 9 12 29 7 26 41 2 66 69 4 1 22 41 69 41 10 23 73 16 53 0 15 17 22 13 83 51 13 11 69 27 12 18 49 0 0 22 83 8 29 35 69 26 13 22 73 22 38 23 26 13 95 73 7 47 0 78 0 18 27 7 47 69 25 4 0 73 18 103 3 1 23 30 5 22 52 22 78 18 18 26 7 34 9 15 11 23 69 83 38 11 10 69 23 8 1 44 11 11 22 0 73 16 40 19 11 23 22 13 83 51 13 11 69 18 11 10 52 22 66 69 4 1 26 43 0 78 4 83 4 26 32 13 26 28 83 30 26 41 1 78 22 4 12 3 51 69 1 19 22 27 83 51 13 11 69 4 8 7 34 23 29 75 83 73 39 47 0 0 69 52 6 23 103 22 15 12 23 69 83 96 41 11 17 83 29 27 34 23 11 69 17 12 83 43 12 9 13 7 69 84 103 4 0 1 83 29 27 34 23 11 69 4 8 0 103 9 7 2 27 29 93 103 69 41 10 23 73 0 38 18 78 13 28 30 83 32 10 1 1 83 29 27 34 69 2 12 20 1 7 103 18 15 22 93 73 83 0 10 10 69 7 1 22 41 69 29 0 3 8 1 38 17 11 1 83 29 27 34 69 2 12 20 1 7 103 3 28 10 30 73 7 47 0 78 1 18 27 24 41 0 29 22 93 73 83 0 10 10 69 16 8 31 43 0 10 69 7 1 22 103 9 7 2 27 29 83 96 1 15 28 95 78 83 38 11 10 69 7 1 22 103 1 15 23 24 7 22 52 22 78 13 22 73 16 38 9 2 0 23 73 84 41 12 9 13 7 71 84 103 69 58 13 6 26 83 34 19 11 11 26 7 20 103 6 15 8 22 69 83 38 11 10 69 30 6 1 41 12 0 2 83 15 28 43 9 1 18 22 13 83 106 72 78 17 27 12 83 33 12 28 22 7 73 23 38 28 64 111 121 61 27 34 11 78 34 28 13 83 52 4 7 1 95 73 84 11 0 26 69 7 1 22 53 0 78 7 22 73 18 103 1 1 8 22 73 26 41 69 26 13 22 73 30 46 1 10 9 22 73 28 33 69 26 13 22 73 4 38 17 11 23 0 69 83 51 10 78 22 22 25 18 53 4 26 0 83 6 29 34 69 12 10 23 16 83 40 3 78 18 18 29 22 53 69 8 23 28 4 83 51 13 11 69 28 29 27 34 23 64 66 83 73 50 41 1 78 22 28 73 26 51 69 6 4 3 25 22 41 0 10 95 83 73 52 40 1 78 8 18 13 22 103 17 6 0 83 13 28 42 0 66 69 18 7 23 103 12 26 69 0 12 3 38 23 15 17 22 13 83 51 13 11 69 4 8 7 34 23 78 4 17 6 5 34 69 26 13 22 73 23 40 8 11 69 21 27 28 42 69 26 13 22 73 4 38 17 11 23 83 11 22 43 10 25 69 26 29 93 103 69 41 10 23 73 16 38 9 2 0 23 73 7 47 0 78 1 28 4 22 103 66 26 13 22 73 0 44 28 64 66 83 73 54 49 0 0 12 29 14 83 36 4 3 0 95 73 18 41 1 78 8 28 27 29 46 11 9 69 21 6 31 43 10 25 0 23 73 94 106 69 26 13 22 73 0 34 6 1 11 23 73 23 38 28 64 111 121 61 27 34 11 78 34 28 13 83 52 4 7 1 95 73 84 11 0 26 69 7 1 22 103 18 15 17 22 27 83 50 11 10 0 1 73 7 47 0 78 22 24 16 83 37 0 78 2 18 29 27 34 23 11 1 83 0 29 51 10 78 4 83 26 26 41 2 2 0 83 11 18 52 12 0 73 83 26 28 103 17 6 4 7 73 7 47 0 78 1 1 16 83 43 4 0 1 83 4 18 62 69 15 21 3 12 18 53 75 73 69 83 40 29 35 69 29 10 83 0 7 103 13 15 21 3 12 29 34 1 84 69 7 1 22 103 18 15 17 22 27 83 50 11 10 0 1 73 7 47 0 78 22 24 16 83 48 4 29 69 20 8 7 47 0 28 0 23 73 26 41 17 1 69 26 29 0 103 7 15 22 26 7 95 103 4 0 1 83 29 27 34 69 10 23 10 73 31 38 11 10 69 18 25 3 34 4 28 0 23 71 83 103 34 1 1 83 10 18 43 9 11 1 83 29 27 34 69 10 23 10 73 31 38 11 10 69 84 29 27 34 69 11 4 1 29 27 107 66 78 4 29 13 83 51 13 11 69 17 8 0 46 11 78 10 21 73 7 47 0 78 18 18 29 22 53 69 6 0 83 10 18 43 9 11 1 83 78 7 47 0 78 22 22 8 93 96 69 78 34 28 13 83 52 4 25 69 27 6 4 103 2 1 10 23 73 26 51 69 25 4 0 71 83 103 49 6 0 29 73 52 40 1 78 22 18 0 23 107 69 73 41 22 29 83 51 13 11 69 22 8 1 51 13 78 7 1 0 29 32 69 8 10 1 29 27 103 19 11 2 22 29 18 51 12 1 11 73 73 22 49 0 28 28 83 2 26 41 1 78 10 21 73 3 43 4 0 17 83 29 27 38 17 78 7 22 8 1 52 69 29 0 22 13 83 38 11 10 69 22 31 22 53 28 78 14 26 7 23 103 10 8 69 21 27 6 46 17 78 17 1 12 22 103 10 0 69 22 8 1 51 13 78 17 27 8 7 103 7 11 4 1 26 83 33 23 27 12 7 73 4 46 17 6 69 26 29 0 103 22 11 0 23 73 26 41 69 7 17 93 78 83 103 36 0 1 83 26 28 103 12 26 69 27 8 3 55 0 0 0 23 83 83 103 17 6 0 83 12 18 53 17 6 69 17 27 28 50 2 6 17 83 15 28 53 17 6 69 22 31 22 53 28 78 14 26 7 23 103 10 8 69 3 5 18 41 17 78 17 27 8 7 103 7 11 4 1 26 83 52 0 11 1 83 8 29 35 69 11 19 22 27 10 103 14 7 11 23 73 28 33 69 8 23 6 0 7 103 17 28 0 22 73 28 41 69 11 4 1 29 27 103 17 6 4 7 73 17 34 4 28 22 83 15 1 50 12 26 69 4 0 7 47 69 7 17 0 73 0 34 0 10 69 26 7 83 46 17 64 69 83 46 28 35 69 29 4 4 73 27 40 18 78 2 28 6 23 103 12 26 69 4 8 0 105 69 78 32 5 12 29 46 11 9 69 16 8 30 34 73 78 4 29 13 83 42 10 28 11 26 7 20 103 3 1 9 31 6 4 34 1 78 72 94 73 7 47 0 78 17 27 0 1 35 69 10 4 10 71 121 77 49 6 0 29 73 52 40 1 78 22 18 0 23 125 69 73 41 22 29 83 51 13 11 23 22 73 17 34 69 2 12 20 1 7 52 69 7 11 83 29 27 34 69 10 10 30 12 83 40 3 78 17 27 12 83 52 14 23 73 83 29 28 103 22 11 21 18 27 18 51 0 78 1 18 16 83 33 23 1 8 83 7 26 32 13 26 75 83 73 63 34 17 78 17 27 12 30 103 8 15 23 24 73 7 47 0 78 3 26 17 22 35 69 26 12 30 12 0 107 69 26 13 22 73 23 38 28 29 69 18 7 23 103 17 6 0 83 16 22 38 23 29 73 83 8 29 35 69 29 0 1 31 22 103 4 29 69 31 28 30 46 11 15 23 26 12 0 103 12 0 69 7 1 22 103 1 1 8 22 73 28 33 69 26 13 22 73 0 44 28 66 69 7 6 83 52 13 11 1 83 5 26 32 13 26 69 6 25 28 41 69 26 13 22 73 22 38 23 26 13 93 78 83 103 36 0 1 83 26 28 103 12 26 69 27 8 3 55 0 0 0 23 83 83 103 34 1 1 83 4 18 35 0 78 17 27 12 83 51 18 1 69 20 27 22 38 17 78 9 26 14 27 51 22 66 69 7 1 22 103 2 28 0 18 29 22 53 69 1 11 22 73 7 40 69 9 10 5 12 1 41 69 26 13 22 73 23 38 28 66 69 18 7 23 103 17 6 0 83 5 22 52 22 11 23 83 6 29 34 69 26 10 83 14 28 49 0 28 11 83 29 27 34 69 0 12 20 1 7 124 69 15 11 23 73 27 34 69 3 4 23 12 83 51 13 11 69 0 29 18 53 22 64 69 83 46 28 35 69 29 0 7 73 7 47 0 3 69 26 7 83 51 13 11 69 23 6 30 34 69 1 3 83 29 27 34 69 29 14 10 69 83 51 10 78 22 27 12 23 103 9 7 2 27 29 83 50 21 1 11 83 29 27 34 69 11 4 1 29 27 107 69 26 10 83 14 28 49 0 28 11 83 29 27 34 69 10 4 10 73 18 41 1 78 17 27 12 83 41 12 9 13 7 69 83 38 11 10 69 7 6 83 52 0 30 4 1 8 7 34 69 26 13 22 73 31 46 2 6 17 83 15 1 40 8 78 17 27 12 83 35 4 28 14 29 12 0 52 75 78 69 52 6 23 103 22 15 18 83 1 28 48 69 9 10 28 13 83 46 17 78 18 18 26 93 103 69 43 19 22 7 26 41 2 78 6 18 4 22 107 69 15 11 23 73 30 40 23 0 12 29 14 83 33 10 2 9 28 30 22 35 69 67 72 83 29 27 34 69 8 10 6 27 7 47 69 10 4 10 71 121 77 49 6 0 29 73 52 40 1 78 22 18 0 23 107 69 73 41 22 29 83 51 13 11 69 4 8 7 34 23 78 17 22 12 30 103 18 7 17 27 73 18 41 69 15 7 6 7 23 38 11 13 0 83 6 21 103 9 7 19 26 7 20 103 6 28 0 18 29 6 53 0 29 73 83 8 29 35 69 1 11 83 29 27 34 69 11 4 1 29 27 103 9 11 17 83 11 26 53 1 29 69 21 5 10 103 7 11 11 22 8 7 47 69 26 13 22 73 23 40 8 11 69 28 15 83 51 13 11 69 0 2 10 105 66 78 69 50 7 23 103 22 1 69 26 29 83 47 4 30 21 22 7 22 35 95 78 69 52 6 23 103 6 28 0 18 29 22 35 69 26 13 22 73 20 53 0 15 17 83 26 22 38 69 3 10 29 26 7 34 23 29 69 18 7 23 103 4 2 9 83 2 26 41 1 29 69 28 15 83 52 18 7 8 30 0 29 32 69 13 23 22 8 7 50 23 11 22 83 30 26 51 13 78 18 27 0 16 47 69 26 13 22 73 4 38 17 11 23 83 29 22 34 8 29 73 83 8 29 35 69 15 9 31 73 24 46 11 10 22 83 6 21 103 18 7 11 20 12 23 103 7 7 23 23 26 93 103 69 41 10 23 73 0 38 18 78 13 28 30 83 32 10 1 1 83 0 7 103 18 15 22 95 73 18 41 1 78 34 28 13 83 37 9 11 22 0 12 23 103 17 6 0 30 69 83 52 4 23 12 29 14 95 103 66 44 0 83 15 22 53 17 7 9 22 69 83 42 16 2 17 26 25 31 62 73 78 4 29 13 83 33 12 2 9 83 29 27 34 69 25 4 7 12 1 103 10 8 69 7 1 22 103 22 11 4 0 82 83 38 11 10 69 31 12 7 103 17 6 0 83 11 26 53 1 29 69 30 28 31 51 12 30 9 10 73 28 41 69 26 13 22 73 22 38 23 26 13 93 78 83 103 32 24 0 29 0 29 32 69 13 4 30 12 95 103 4 0 1 83 4 28 53 11 7 11 20 73 21 40 9 2 10 4 12 23 103 72 67 69 7 1 22 103 3 7 3 7 1 83 35 4 23 75 121 99 39 47 0 0 69 52 6 23 103 22 15 12 23 69 83 96 41 11 17 83 29 27 34 69 11 4 1 29 27 103 7 28 12 29 14 83 33 10 28 17 27 73 18 43 9 78 14 26 7 23 52 69 1 3 83 5 26 49 12 0 2 83 10 1 34 4 26 16 1 12 0 125 69 13 4 7 29 31 34 73 78 6 1 12 22 55 12 0 2 83 29 27 46 11 9 22 95 73 18 41 1 78 18 26 5 23 103 4 0 12 30 8 31 52 69 1 3 83 8 31 43 69 5 12 29 13 0 105 66 78 69 50 7 23 103 22 1 69 26 29 83 47 4 30 21 22 7 22 35 95 78 69 52 6 23 103 8 15 1 22 73 18 43 9 78 14 26 7 23 52 69 1 3 83 30 26 43 1 78 4 29 0 30 38 9 29 73 83 8 31 43 69 5 12 29 13 0 103 10 8 69 16 8 7 51 9 11 73 83 8 29 35 69 15 9 31 73 24 46 11 10 22 83 6 21 103 6 28 0 22 25 26 41 2 78 17 27 0 29 32 22 78 10 21 73 7 47 0 78 0 18 27 7 47 75 78 69 52 6 23 103 22 15 18 83 1 28 48 69 9 10 28 13 83 46 17 78 18 18 26 93 103 69 58 13 22 7 83 0 10 10 69 0 8 26 35 95 78 66 63 12 7 103 16 29 69 30 8 24 34 69 3 4 29 73 26 41 69 1 16 1 73 26 42 4 9 0 95 73 18 33 17 11 23 83 6 6 53 69 2 12 24 12 29 34 22 29 75 83 73 63 34 17 78 17 27 12 30 103 13 15 19 22 73 23 40 8 7 11 26 6 29 103 10 24 0 1 73 7 47 0 78 3 26 26 27 103 10 8 69 7 1 22 103 22 11 4 95 73 7 47 0 78 7 26 27 23 52 69 1 3 83 29 27 34 69 15 12 1 69 83 38 11 10 69 7 1 22 103 6 15 17 7 5 22 107 69 15 11 23 73 28 49 0 28 69 18 5 31 103 17 6 0 83 30 26 43 1 78 4 29 0 30 38 9 29 69 18 7 23 103 4 2 9 83 29 27 34 69 13 23 22 8 7 50 23 11 22 83 29 27 38 17 78 6 1 8 4 43 69 1 11 83 29 27 34 69 9 23 28 28 29 35 75 73 69 83 46 28 35 69 13 23 22 8 7 34 1 78 8 18 7 83 46 11 78 13 26 26 83 46 8 15 2 22 82 83 46 11 78 17 27 12 83 35 12 24 12 29 12 83 46 8 15 2 22 73 27 34 69 13 23 22 8 7 34 1 78 13 26 4 72 103 8 15 9 22 73 18 41 1 78 3 22 4 18 43 0 78 13 22 73 16 53 0 15 17 22 13 83 51 13 11 8 93 73 83 0 10 10 69 17 5 22 52 22 11 1 83 29 27 34 8 66 69 0 8 10 46 11 9 95 83 78 49 34 69 8 0 1 29 26 43 0 78 4 29 13 83 42 16 2 17 26 25 31 62 94 78 3 26 5 31 103 17 6 0 83 12 18 53 17 6 69 18 7 23 103 22 27 7 23 28 22 103 12 26 75 83 73 59 38 19 11 69 23 6 30 46 11 7 10 29 73 28 49 0 28 69 7 1 22 103 3 7 22 27 73 28 33 69 26 13 22 73 0 34 4 66 69 7 1 22 103 7 7 23 23 26 83 40 3 78 17 27 12 83 38 12 28 73 83 8 29 35 69 15 9 31 73 7 47 0 78 9 26 31 26 41 2 78 17 27 0 29 32 22 78 17 27 8 7 103 8 1 19 22 73 28 41 69 26 13 22 73 22 38 23 26 13 93 78 83 103 34 1 1 83 8 31 52 10 78 22 18 0 23 125 69 73 54 22 12 95 103 44 78 2 26 31 22 103 28 1 16 83 12 5 34 23 23 69 0 12 22 35 72 12 0 18 27 26 41 2 78 21 31 8 29 51 69 15 9 31 73 28 49 0 28 69 7 1 22 103 0 15 23 7 1 83 38 11 10 69 22 31 22 53 28 78 17 1 12 22 103 17 6 4 7 73 27 38 22 78 22 22 12 23 106 7 11 4 1 0 29 32 69 8 23 6 0 7 103 10 0 69 26 29 83 51 10 78 7 22 73 10 40 16 28 69 21 6 28 35 94 78 4 29 13 83 51 10 78 4 31 5 83 51 13 11 69 18 7 26 42 4 2 22 83 6 21 103 17 6 0 83 5 18 41 1 66 69 18 5 31 103 17 6 0 83 11 26 53 1 29 69 28 15 83 51 13 11 69 18 0 1 107 69 15 11 23 73 18 43 9 78 17 27 12 83 43 12 24 12 29 14 83 36 23 11 4 7 28 1 34 22 78 17 27 8 7 103 6 28 4 4 5 83 40 11 78 17 27 12 83 32 23 1 16 29 13 95 103 44 78 2 26 31 22 103 4 2 9 83 29 27 34 69 9 23 22 12 29 103 21 2 4 29 29 0 103 3 1 23 83 15 28 40 1 64 66 83 73 50 41 1 78 22 28 73 26 51 69 6 4 3 25 22 41 0 10 75 83 73 52 40 1 78 9 28 6 24 34 1 78 4 7 73 22 49 0 28 28 7 1 26 41 2 78 13 22 73 27 38 1 78 8 18 13 22 107 69 15 11 23 73 27 34 69 8 10 6 7 23 103 12 26 69 5 12 1 62 69 9 10 28 13 93 103 69 43 19 22 7 26 41 2 78 6 18 4 22 107 69 15 11 23 73 30 40 23 0 12 29 14 83 33 10 2 9 28 30 22 35 69 67 72 83 29 27 34 69 29 12 11 29 27 103 1 15 28 93 99 121 19 13 27 22 83 29 27 34 69 6 0 18 31 22 41 22 78 4 29 13 83 51 13 11 69 22 8 1 51 13 78 4 29 13 83 38 9 2 69 7 1 22 46 23 78 4 1 27 18 62 69 25 0 1 12 83 36 10 3 21 31 12 7 34 1 64 69 83 58 26 41 6 11 69 28 7 83 51 13 11 69 0 12 5 34 11 26 13 83 13 18 62 69 41 10 23 73 4 38 22 78 3 26 7 26 52 13 11 1 83 30 26 51 13 78 17 27 12 83 48 10 28 14 83 1 22 103 13 15 1 83 11 22 34 11 78 1 28 0 29 32 73 78 13 22 73 1 34 22 26 0 23 73 28 41 69 26 13 22 73 0 34 19 11 11 7 1 83 35 4 23 69 21 27 28 42 69 15 9 31 73 7 47 0 78 18 28 27 24 103 13 11 69 27 8 23 103 16 0 1 22 27 7 38 14 11 11 93 73 83 20 10 78 34 28 13 83 37 9 11 22 0 12 23 103 17 6 0 83 26 22 49 0 0 17 27 73 23 38 28 78 4 29 13 83 42 4 10 0 83 0 7 103 13 1 9 10 69 83 37 0 13 4 6 26 22 103 10 0 69 26 29 83 47 0 78 23 22 26 7 34 1 78 3 1 6 30 103 4 2 9 83 29 27 34 69 25 10 1 2 83 47 0 78 13 18 13 83 35 10 0 0 83 0 29 103 6 28 0 18 29 26 40 11 64 69 83 58 6 36 13 78 12 0 73 7 47 0 78 22 7 6 1 62 69 1 3 83 29 27 34 69 6 0 18 31 22 41 22 78 4 29 13 83 51 13 11 69 22 8 1 51 13 78 4 7 73 7 47 0 7 23 83 10 1 34 4 26 12 28 7 93

About these ads

Pages: 1 2 3

8 Responses to “Creation”

  1. Jebb said

    Can’t believe nobody else commented on this… That one was a lot of fun!
    I took a different approach from the proposed Scheme solution, went for a dictionary attack:

    #!/usr/bin/python
    
    def read_cipher(textFile):
    	'''Takes the name of the file containing the encrypted text as argument,
    	returns the list of ascii ordinals'''
    	f = open(textFile, 'r')
    	returnList = [int(a) for a in f.read().split()]
    	f.close()
    	return returnList
    
    def decrypt(ordList, password):
    	'''This function XORs a text with the code (both as list of ordinals!!)
    	and returns the encoded/decoded list of ordinals'''
    	from itertools import cycle
    	decryptedList = [a^ord(b) for a,b in zip(ordList, cycle(password))]
    	return decryptedList
    
    def make_attack_dictionary(dictFile):
    	f = open(dictFile,'r')
    	returnDict = attack_dictionary(f.read().split())
    	f.close()
    	return returnDict
    
    def attack_dictionary(rawDict):
    	'''Takes a list of words as argument, and produces an attack dictionary
    	from it: with added case variations (also capitalizes the words that
    	only exist as small case in the initial list), and sorted by length'''
    	from string import capitalize
    	# Generate a dict of already capitalized words in the raw dictionary
    	capWords = {}
    	for word in rawDict:
    		if word == capitalize(word):
    			capWords[word] = 1
    	# Now capitalize the rest of them; this works in O(n) because capWords
    	# is a dict
    	complementDict = [capitalize(word) for word in rawDict if not word in capWords]
    	# Finally, merge and sort the attack dictionary by word length
    	return sorted(rawDict + complementDict, key=len)
    
    def words_found(text, dictionary):
    	'''Returns the number of known words (from dictionary) found in text'''
    	from re import findall
    	wordCount = 0
    	for word in findall(r'\w\w+', text): 
    		if word in dictionary:
    			wordCount +=1
    	return wordCount
    
    def attack(cipherText):
    	'''Performs a dictionary attack on an encrypted text, passed as a
    	list of integers'''
    	attackDict = make_attack_dictionary('/usr/share/dict/words')
    # We'll also build a dict purely for performance reasons
    	compareDict = {}
    	for word in attackDict:
    		compareDict[word] = 1
    # Tweak these parameters for the dictionary attack
    	attackDepth = 50
    	attackLengthMax = 8
    	attackThreshold = 6
    # Now try all passwords of length <= attackLengthMax,
    # scanning the first attackDepth characters in cipherText
    # and print something when finding more than attackThreshold known words
    	for password in attackDict:
    		if len(password) > attackLengthMax: break
    		decryptedText = "".join([chr(a) 
    				for a in decrypt(cipherText[:attackDepth], password)])
    		wordsFound = words_found(decryptedText, compareDict)
    		if wordsFound >= attackThreshold:
    			print '%d matches found with %s' % (wordsFound, password)
    
    if __name__ == '__main__':
    	cipherText = read_cipher('text')
    	attack(cipherText)
    	print 'Password to try?'
    	password = raw_input()
    	print "".join([chr(a) for a in decrypt(cipherText, password)])
    

    Basically, I start by building an attack dictionary, sorted by length. Then I brute-force my way through this attack dictionary, trying to decrypt the beginning of the encrypted text using each one of the possible passwords, and I count the number of real words I can find in the decrypted version.

    Of course it could probably be automated completely by simply returning the password yielding the highest number of real words, but it works for me like that. Running it as it is shown here (scanning the first 50 letters of the encrypted text, and trying passwords up to 8 letters long), it shows me the list of following possible keys (only showing the keys producing 6 or more known words):
    6 matches found with imber
    6 matches found with infer
    6 matches found with inker
    6 matches found with ceresin
    6 matches found with chooser
    6 matches found with geronto
    6 matches found with oenolin
    6 matches found with Allower
    6 matches found with Ceresin
    6 matches found with Chooser
    6 matches found with Foresin
    8 matches found with Genesis
    6 matches found with Geronto
    6 matches found with Getaway
    6 matches found with Subjoin
    6 matches found with Thrower
    6 matches found with Vetiver

  2. Graham said

    I followed the ideas of the solution here, but wished to automate the process
    a bit more. I had my code try different passwords (given by assuming that space
    is the most common character), checking those words against membership in my
    system’s dict file. It outputs all possibilities, so it still requires a human
    eye to sort through the gobbledygook.

    #!/usr/bin/env python
    
    from collections import Counter
    from pprint import pprint
    
    def split_n(seq, n):
        """Split sequence into groupings by every nth item"""
        return (seq[i::n] for i in xrange(n))
    
    def most_freq(seq):
        """Most frequent item in sequence"""
        return Counter(seq).most_common(1)[0][0]
    
    def pass_n(c_text, n):
        """Assume that most frequent item is a space (with ord 32); return a
        password of length n from those most frequent items in """
        most_freqs = (most_freq(seq) for seq in split_n(c_text, n))
        return ''.join(chr(x ^ 32) for x in most_freqs)
    
    def decipher(c_text, password):
        """Given a password, use it to give clear text"""
        return ''.join(chr(x ^ ord(y)) for (x, y) in zip(c_text,
            password * (len(c_text) / len(password))))
    
    def decrypt(c_text, dictionary):
        """Given a dictionary of words, try successive ns in pass_n until the
        password is in dictionary. Then, return deciphered text via decipher."""
        possibles = []
        for n in xrange(len(max(dictionary, key=lambda word: len(word)))):
            password = pass_n(c_text, n)
            if password.lower() in dictionary:
                possibles.append((n, password, decipher(c_text, password)))
        return possibles
    
    if __name__ == "__main__":
        with open("creation_ctext.txt") as C_FILE:  # Numbers in single line file
            C_TEXT = [int(x) for x in C_FILE.read().split()]
            with open("/usr/share/dict/web2") as DICT_FILE:
                DICTIONARY = set(line.strip() for line in DICT_FILE.readlines())
                pprint(decrypt(C_TEXT, DICTIONARY))
    
  3. programmingpraxis said

    If you are really interested in automating this program fully, Google for ‘Kasiski examination’ and go from there. Like a lot of these things, it’s named for the wrong man; Charles Babbage figured it out twenty years before Kasiski.

  4. Graham said

    Interesting stuff! It’s reminiscent of some of Simon Singh’s “The Code Book,” a decent source and fun read.

  5. kawas said

    Like others I want to automate the process as much as possible.
    So my slightly different implementation returns a password and a “confidence number” based on the frequencies of “” and “e”.
    Then we can search for all passwords given a maximum length and a confidence threshold.

    Clojure code:

    (defn read-cipher [filepath]
      (map #(Integer/parseInt %) (seq (.split (slurp filepath) "\\s+"))))
    
    (defn stripe [text n]
      (for [i (range 0 (count text) n)] (nth text i)))
    
    (defn rsort-freq [text]
      (reverse (sort-by second (frequencies text))))
    
    (defn char-xor [ord1 ord2]
      (char (bit-xor ord1 ord2)))
    
    (defn guess-pass [text nchar]
      (loop [text text pwd [] same 0]
        (if (= nchar (count pwd))
          (vector (apply str pwd) (float (/ same nchar)))
          (let [strp (stripe text nchar)
                [[ord1 _] [ord2 _]] (take 2 (rsort-freq strp))
                letter1 (char-xor (int \space) ord1)
                letter2 (char-xor (int \e) ord2)
                same (if (= letter1 letter2) (inc same) same)]
            (recur (next text) (conj pwd letter1) same)))))
    
    (defn search-pass [filepath max-nchar confidence]
      (let [text (read-cipher filepath)]
        (filter #(< confidence (second %))
          (map #(guess-pass text %) (range 1 (inc max-nchar))))))
    

    For example, we can search for all passwords less than 20 chars with at least 80% confidence:

    user=> (search-pass "praxis/crypted.txt" 20 0.8)
    (["Genesis" 0.85714287])
    

    This one is funny:

    user=> (search-pass "praxis/crypted.txt" 20 0.6)
    (["ess" 0.6666667] ["Genesis" 0.85714287] ["GenesisGenesis" 0.78571427])
    
  6. [...] In their book Software Tools, Brian Kernighan and P. J. Plauger describe a simple command for encrypting files. It works by xor-ing each byte of a file with a byte of the key, extending the key cyclically until it is the same length as the text. The xor operation is symmetric, so only one program is needed to perform both encryption and decryption. This isn’t a particularly secure encryption algorithm; we showed how to break it in one of our earliest exercises. [...]

  7. simonliu2008 said

    I had the similar ideas with Graham, and I improve my script when I saw Graham’s since I am not familiar with Python.

    from collections import Counter

    import string

    def crack(text, n):
    pwd = []

    for seq in [text[i::n] for i in xrange(n)]:
    p = chr(ord(‘ ‘) ^ int(Counter(seq).most_common(1)[0][0]))
    if is_pwd_char(p):
    pwd.append(p)
    else:
    return None

    return pwd

    def is_pwd_char(ch):
    return ch in string.digits or ch in string.ascii_letters

    def decrypt(text, pwd):
    return [chr(ord(pwd[i % len(pwd)]) ^ int(x)) for (i, x) in enumerate(text)]

    if __name__ == ‘__main__’:
    with open(‘/tmp/cipher-text’) as f:
    text = f.read().split()
    for i in range(1, 21):
    pwd = crack(text, i)
    if pwd != None:
    print ‘decrypt with pwd: %s’ % pwd
    print ”.join(decrypt(text, pwd))

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 598 other followers

%d bloggers like this: