1 ){ /* (1) Decrement the depth */ $depth += $decr_factor; /* (2) Try to override the secret file */ if( @file_put_contents(SECRET_CONF, "$key:$depth:$next") ){ slog("Secret depth decremented to $depth", 'cyclic-hash:decr', 'update'); return 0; }else{ slog("Error while decrementing secret depth", 'cyclic-hash:decr', 'update'); return 127; } /* [4] If cannot decrement, use new secret and generate next =========================================================*/ }else{ // Generate new secret $secret = $next.':999:'.generate_secret(); // Try to override the secret file if( @file_put_contents(SECRET_CONF, $secret) ){ slog("Random secret generated successfully", 'cyclic-hash:decr', 'update'); return 0; }else{ slog("Error while generating new random secret", 'cyclic-hash:decr', 'update'); return 127; } } return 0; } // IF received 'revert' as $1 -> increment ELSE decrement (default) $decr_factor = ( $argc < 2 || $argv[1] != 'revert' ) ? -1 : +1; echo cyclichash_decr($decr_factor); ?>