Ported PHP cipher behaves differently than its Python counterpart

Solution:
I'm not sure how Python works, but you can't indefinitely add or subtract from the index of an array in PHP. Once you get to 0 and start subtracting more (assuming the indexes are zero-based and numerical), you're going to get an undefined offset error because that index doesn't exist. The same happens if you increase it more than the maximum index. You might want to do something like modulo to make sure that the value is always in the range of the indexes of the array.
I whipped up a quick PHP script that should do this:
function Offset($offset) {
$array = ["A","B","C","D","E","F","G","H","I","J",
"K","L","M","N","O","P","Q","R","S","T",
"U","V","W","X","Y","Z","a","b","c","d",
"e","f","g","h","i","j","k","l","m","n",
"o","p","q","r","s","t","u","v","w","x",
"y","z","1","2","3","4","5","6","7","8",
"9","0",".",",","'","?","!","@","_","-"];
// Make sure the offset is a +/- value of the indexes of $array
// by taking the modulo
$offset = $offset % (count($array)-1) ;
// If it is a negative number, subtract it from the end instead
if ($offset < 0) {
$offset = count($array)-1 + $offset;
}
// Get the index from your array
return $array[$offset];
}
for ($i=-200; $i<200; $i++) {
echo "$i => ".(Offset($i))."<br>";
}
This outputs:
-200 => K
-199 => L
-198 => M
-197 => N
-196 => O
-195 => P
-194 => Q
-193 => R
-192 => S
-191 => T
-190 => U
-189 => V
-188 => W
-187 => X
-186 => Y
-185 => Z
-184 => a
-183 => b
-182 => c
-181 => d
-180 => e
-179 => f
-178 => g
-177 => h
-176 => i
-175 => j
-174 => k
-173 => l
-172 => m
-171 => n
-170 => o
-169 => p
-168 => q
-167 => r
-166 => s
-165 => t
-164 => u
-163 => v
-162 => w
-161 => x
-160 => y
-159 => z
-158 => 1
-157 => 2
-156 => 3
-155 => 4
-154 => 5
-153 => 6
-152 => 7
-151 => 8
-150 => 9
-149 => 0
-148 => .
-147 => ,
-146 => '
-145 => ?
-144 => !
-143 => @
-142 => _
-141 => -
-140 => A
-139 => B
-138 => C
-137 => D
-136 => E
-135 => F
-134 => G
-133 => H
-132 => I
-131 => J
-130 => K
-129 => L
-128 => M
-127 => N
-126 => O
-125 => P
-124 => Q
-123 => R
-122 => S
-121 => T
-120 => U
-119 => V
-118 => W
-117 => X
-116 => Y
-115 => Z
-114 => a
-113 => b
-112 => c
-111 => d
-110 => e
-109 => f
-108 => g
-107 => h
-106 => i
-105 => j
-104 => k
-103 => l
-102 => m
-101 => n
-100 => o
-99 => p
-98 => q
-97 => r
-96 => s
-95 => t
-94 => u
-93 => v
-92 => w
-91 => x
-90 => y
-89 => z
-88 => 1
-87 => 2
-86 => 3
-85 => 4
-84 => 5
-83 => 6
-82 => 7
-81 => 8
-80 => 9
-79 => 0
-78 => .
-77 => ,
-76 => '
-75 => ?
-74 => !
-73 => @
-72 => _
-71 => -
-70 => A
-69 => B
-68 => C
-67 => D
-66 => E
-65 => F
-64 => G
-63 => H
-62 => I
-61 => J
-60 => K
-59 => L
-58 => M
-57 => N
-56 => O
-55 => P
-54 => Q
-53 => R
-52 => S
-51 => T
-50 => U
-49 => V
-48 => W
-47 => X
-46 => Y
-45 => Z
-44 => a
-43 => b
-42 => c
-41 => d
-40 => e
-39 => f
-38 => g
-37 => h
-36 => i
-35 => j
-34 => k
-33 => l
-32 => m
-31 => n
-30 => o
-29 => p
-28 => q
-27 => r
-26 => s
-25 => t
-24 => u
-23 => v
-22 => w
-21 => x
-20 => y
-19 => z
-18 => 1
-17 => 2
-16 => 3
-15 => 4
-14 => 5
-13 => 6
-12 => 7
-11 => 8
-10 => 9
-9 => 0
-8 => .
-7 => ,
-6 => '
-5 => ?
-4 => !
-3 => @
-2 => _
-1 => -
0 => A
1 => B
2 => C
3 => D
4 => E
5 => F
6 => G
7 => H
8 => I
9 => J
10 => K
11 => L
12 => M
13 => N
14 => O
15 => P
16 => Q
17 => R
18 => S
19 => T
20 => U
21 => V
22 => W
23 => X
24 => Y
25 => Z
26 => a
27 => b
28 => c
29 => d
30 => e
31 => f
32 => g
33 => h
34 => i
35 => j
36 => k
37 => l
38 => m
39 => n
40 => o
41 => p
42 => q
43 => r
44 => s
45 => t
46 => u
47 => v
48 => w
49 => x
50 => y
51 => z
52 => 1
53 => 2
54 => 3
55 => 4
56 => 5
57 => 6
58 => 7
59 => 8
60 => 9
61 => 0
62 => .
63 => ,
64 => '
65 => ?
66 => !
67 => @
68 => _
69 => -
70 => A
71 => B
72 => C
73 => D
74 => E
75 => F
76 => G
77 => H
78 => I
79 => J
80 => K
81 => L
82 => M
83 => N
84 => O
85 => P
86 => Q
87 => R
88 => S
89 => T
90 => U
91 => V
92 => W
93 => X
94 => Y
95 => Z
96 => a
97 => b
98 => c
99 => d
100 => e
101 => f
102 => g
103 => h
104 => i
105 => j
106 => k
107 => l
108 => m
109 => n
110 => o
111 => p
112 => q
113 => r
114 => s
115 => t
116 => u
117 => v
118 => w
119 => x
120 => y
121 => z
122 => 1
123 => 2
124 => 3
125 => 4
126 => 5
127 => 6
128 => 7
129 => 8
130 => 9
131 => 0
132 => .
133 => ,
134 => '
135 => ?
136 => !
137 => @
138 => _
139 => -
140 => A
141 => B
142 => C
143 => D
144 => E
145 => F
146 => G
147 => H
148 => I
149 => J
150 => K
151 => L
152 => M
153 => N
154 => O
155 => P
156 => Q
157 => R
158 => S
159 => T
160 => U
161 => V
162 => W
163 => X
164 => Y
165 => Z
166 => a
167 => b
168 => c
169 => d
170 => e
171 => f
172 => g
173 => h
174 => i
175 => j
176 => k
177 => l
178 => m
179 => n
180 => o
181 => p
182 => q
183 => r
184 => s
185 => t
186 => u
187 => v
188 => w
189 => x
190 => y
191 => z
192 => 1
193 => 2
194 => 3
195 => 4
196 => 5
197 => 6
198 => 7
199 => 8
Answer
Solution:
Who ever commented, thank you. python whenIntI
got into the negatives it just looped back through the array. so i just had to add some statements to catch if IntI had gone bellow 0 or above the length of the array.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: call to undefined function illuminate\encryption\openssl_cipher_iv_length()
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.