Category Archives: Programming
Books!
ChatGPT code explanation
I threw this function:
protected function get_passphrase_list() {
// 2023-03-30 jj5 - we cache the generated passphrase list in a static variable so we don't
// have to constantly regenerate it and because we don't want to put this sensitive data
// into an instance field. If you don't want the passphrase list stored in a static variable
// override this method and implement differently.
static $result = null;
if ( $result !== null ) { return $result; }
$secret_list = $this->get_config_secret_list();
$result = [];
foreach ( $secret_list as $secret ) {
$result[] = $this->calc_passphrase( $secret );
}
return $result;
}
into ChatGPT and it said:
This is a protected function that returns a list of passphrases based on a list of secret values obtained from another function, get_config_secret_list(). The passphrases are generated using a method called calc_passphrase().
The function checks if the passphrase list has already been generated by looking at a static variable named $result. If $result is not null, the function returns it. Otherwise, the function generates the passphrase list and stores it in the $result variable.
The reason for caching the passphrase list in a static variable is to avoid having to regenerate it every time the function is called, which can be time-consuming. Additionally, it is considered a security best practice not to store sensitive data, such as passphrases, in instance fields.
If you want to change the way the passphrase list is stored, you can override this method and implement it differently.
PHP preg_match regex fail
So this happened. Basically the first regex causes preg_match to fail when it tries to process 128KiB ASCII zeros… and 128KiB isn’t really that many zeros. Fortunately the second regex performs much better, PHP runs out of memory before preg_match chokes on that one.
-------------------
Sat Apr 01 13:17:17 [bash:5.1.16 jobs:0 error:0 time:243]
jj5@charm:/home/jj5/desktop/experiment
$ cat base64-regex.php
<?php
test( '/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{4})$/' );
test( '/^[a-zA-Z0-9\/+]{2,}={0,2}$/' );
function test( $regex ) {
echo "testing: $regex\n";
$n = 0;
for ( ;; ) {
$n++;
echo "n: $n\n";
$string = str_repeat( '0', pow( 2, $n ) );
$base64 = base64_encode( $string );
if ( preg_match( $regex, $base64 ) ) { continue; }
echo "error at N = $n.\n";
return;
}
}
-------------------
Sat Apr 01 13:17:21 [bash:5.1.16 jobs:0 error:0 time:247]
jj5@charm:/home/jj5/desktop/experiment
$ php base64-regex.php
testing: /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{4})$/
n: 1
n: 2
n: 3
n: 4
n: 5
n: 6
n: 7
n: 8
n: 9
n: 10
n: 11
n: 12
n: 13
n: 14
n: 15
n: 16
n: 17
error at N = 17.
testing: /^[a-zA-Z0-9\/+]{2,}={0,2}$/
n: 1
n: 2
n: 3
n: 4
n: 5
n: 6
n: 7
n: 8
n: 9
n: 10
n: 11
n: 12
n: 13
n: 14
n: 15
n: 16
n: 17
n: 18
n: 19
n: 20
n: 21
n: 22
n: 23
n: 24
n: 25
n: 26
n: 27
n: 28
n: 29
n: 30
n: 31
n: 32
n: 33
n: 34
n: 35
Killed
-------------------
Sat Apr 01 13:18:21 [bash:5.1.16 jobs:0 error:137 time:307]
Announcing Kickass Crypto
I’m working on a PHP encryption library called Kickass Crypto.
The Linux man-pages project
Today I discovered: The Linux man-pages project.
The Six Dumbest Ideas in Computer Security
This is good: The Six Dumbest Ideas in Computer Security.
It referenced this, which is also good: Personal observations on the reliability of the Shuttle by R.P. Feynman.
OWASP SCP Quick Reference Guide v2
Had a quick read of this old chestnut: OWASP SCP Quick Reference Guide v2.
The Unpredictable Abilities Emerging From Large AI Models
Today I read The Unpredictable Abilities Emerging From Large AI Models and clicked through to read 137 emergent abilities of large language models.
SPI: The serial peripheral interface
Watched this one from Ben Eater: SPI: The serial peripheral interface. I found it while watching this one: Hacking a weird TV censoring device, which was kind of hilarious, he reverses a profanity filter and finds its dictionary.
I noticed Ben Eater has a Keysight DSOX1204G Oscilloscope, a pretty nice looking bit of kit. Oh dear, he also seems to have a Keysight DSOX4024A Oscilloscope, which is an even nicer looking bit of kit.
When I have some time I’m gonna get some of these BME280 knockoffs and see if I can play along with the SPI video.