Skip to content

Instantly share code, notes, and snippets.

@karlgluck
karlgluck / Hash Ladders for Shorter Lamport Signatures.md
Last active March 31, 2024 17:53
I describe a method for making Lamport signatures take up less space. I haven't seen anyone use hash chains this way before, so I think it's pretty cool.

What's this all about?

Digital cryptography! This is a subject I've been interested in since taking a class with Prof. Fred Schneider back in college. Articles pop up on Hacker News fairly often that pique my interest and this technique is the result of one of them.

Specifically, this is about Lamport signatures. There are many signature algorithms (ECDSA and RSA are the most commonly used) but Lamport signatures are unique because they are formed using a hash function. Many cryptographers believe that this makes them resistant to attacks made possible by quantum computers.

How does a Lamport Signature work?

learn Unreal Engine 5 (UE5 https://www.unrealengine.com) - free pro software, this is what the industry uses now
get it from the Epic Games Launcher https://store.epicgames.com/
do projects alone at first. take time to learn the basics. multiplayer is always more complicated.
buying asset store projects is an unreasonably effective way to learn https://www.unrealengine.com/marketplace
learning projects should be simple enough to finish.
blueprints is a programming language for games used by UE5. Many games are possible using only blueprints code. start by searching for “beginner blueprint tutorials ue5”
find a good place to ask questions, like a Discord community or https://forums.unrealengine.com/
@karlgluck
karlgluck / VectorMagnitude.md
Created October 13, 2017 05:11
Approximate magnitude of 2d and 3d vectors

Vec3 Magnitude

These C# implementations of approximate magnitude with no square roots are actually slower than calling a native implementation in Unity, but if this were implemented intelligently in C there's a good chance they would be faster. In any case, they're here because it was a pain to get the magic numbers.

Accurate to within 4.5%.


public static float MagnitudeFast (this Vector2 self)
    {
# This will register a new job that removes itself from Get-ScheduledJob when finished
$Trigger = New-JobTrigger -Once -At (Get-Date).AddSeconds(3)
$TaskName = "SelfDestructingJob"
Register-ScheduledJob -Trigger $Trigger -Name $TaskName `
-ScriptBlock ([scriptblock]::Create(@"
("Started job at " + (Get-Date) + ", waiting...") | Out-File -FilePath 'C:\ProofThatItWorks.txt'
Start-Sleep 3
("Finished at " + (Get-Date)) | Out-File -Append -FilePath 'C:\ProofThatItWorks.txt'
Unregister-ScheduledJob -Name '$TaskName' -Force
@karlgluck
karlgluck / WaitForScheduledTaskExample.ps1
Last active May 15, 2022 21:18
Example of how to wait for a scheduled task to finish running
$Trigger = New-JobTrigger -Once -At (get-date).AddSeconds(5)
$JobOptions = New-ScheduledJobOption -StartIfOnBattery -RunElevated
$Job = Register-ScheduledJob -Name "TaskName" -Trigger $Trigger -ScheduledJobOption $JobOptions `
-ScriptBlock {
Sleep 5
}
# From https://docs.microsoft.com/en-us/windows/win32/taskschd/task-scheduler-error-and-success-constants?redirectedfrom=MSDN
Set-Variable -Name "SCHED_S_TASK_HAS_NOT_RUN" -Value 0x00041303 -Option Constant
@karlgluck
karlgluck / RunAtLoginExample.ps1
Created May 15, 2022 19:02
How to register a script block to run with elevated privileges when the current user logs in
$JobName = "RunAtLoginExample"
$Enabled = $True # set to $False and run to remove the job
# https://stackoverflow.com/questions/40569045/register-scheduledjob-as-the-system-account-without-having-to-pass-in-credentia
# Output: %LOCALAPPDATA%\Microsoft\Windows\PowerShell\ScheduledJobs\$JobName
$accountId = ((Get-WMIObject -class Win32_ComputerSystem | Select-Object -ExpandProperty username))
$Trigger = New-JobTrigger -AtLogOn
$JobOptions = New-ScheduledJobOption -StartIfOnBattery -RunElevated
@karlgluck
karlgluck / CreatePathIfDoesntExistExample.ps1
Created May 14, 2022 19:57
One-liner to create a path if it doesn't exist
if (-not (Test-Path $Path)) { New-Item $Path -ItemType Directory | Out-Null }
@karlgluck
karlgluck / ExtractFileFromZipExample.ps1
Created May 14, 2022 17:46
How to extract a single file from a ZIP archive using Powershell
$ZipFilePath = ""
$FileNameInZip = ""
Add-Type -AssemblyName System.IO.Compression.FileSystem
$Zip = [System.IO.Compression.ZipFile]::OpenRead($ZipFilePath)
$Zip.Entries |
Where-Object { $_.Name -eq $FileNameInZip } |
ForEach-Object {
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($_, $_.Name, $true)
@karlgluck
karlgluck / DownloadFromPrivateGitHubRepoExample.ps1
Created May 14, 2022 17:32
One-liner for downloading from a private GitHub repository
# Fill these in with your own values
$Username = "your_username"
$Branch = "main"
$PathToFile = "README.md"
# Go to [https://github.com/settings/tokens] and add a Personal Access Token with two scopes: "repo" and "read:org"
$GitHubAuthToken = "ghp_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Invoke-WebRequest -Method Get -Uri "https://raw.githubusercontent.com/$Username/$Repository/$Branch/$PathToFile" -Headers @{Authorization="token $GitHubAuthToken"; 'Cache-Control'='no-cache'} | ForEach-Object { $_.Content } | Write-Host
@karlgluck
karlgluck / How to Access Data in the Backbuffer in Direct3D 9.cpp
Created January 17, 2014 03:35
This is the code for accessing pixel data from the backbuffer in a D3D9 application. Keywords: LPDIRECT3DSURFACE9 read backbuffer copy back buffer directly access back buffer Direct3D device DirectX 9
void demoExtractBackBufferPixels(LPDIRECT3DDEVICE9 d3d_device) {
// TODO: In your app, add FAILED() macros to check the HRESULTs passed back
// by each of the API calls. I leave these out for clarity.
// Grab the backbuffer from the Direct3D device
LPDIRECT3DSURFACE9 back_buffer = NULL;
d3d_device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &back_buffer);
// Get the buffer's description and make an offscreen surface in system memory.