β‘ Code Style Transformation Engine β‘
H-Code rewrites AI-generated source into code that reads like a human wrote it β preserving syntax, behavior, and intent while restoring the natural inconsistency real developers leave behind.
Demo Β· Quick Start Β· API Β· How It Works Β· Ethics
Built with PHP, vanilla JS, and a healthy respect for the LLM token budget.
- β¨ Features
- π§ How It Works
- π Architecture
- π Supported Languages
- π Quick Start
- βοΈ Configuration
- π₯ Web UI
- π API Reference
- π PHP Library
- π Intensity Levels
- π¬ Transformations Applied
- π Troubleshooting
- βοΈ Responsible Use
- π Limitations
- πΊ Roadmap
- π€ Contributing
- π§ͺ Testing
- π License
- π¬ Acknowledgments
|
|
Input (AI-generated, suspiciously tidy):
function calculateTotal(items) {
let total = 0;
for (let i = 0; i < items.length; i++) {
const item = items[i];
if (item.price > 0 && item.quantity > 0) {
total += item.price * item.quantity;
}
}
return total;
}Output (H-Code, intensity 75):
function calculateTotal(items) {
// skipping items with zero price/qty, common edge case
let total = 0
for (let i = 0; i < items.length; i++) {
const item = items[i];
if (item.price > 0 && item.quantity > 0) {
total = total + (item.price * item.quantity)
}
}
// console.log("total was", total) // left from testing
return (total);
}Same logic. Same output. Indentation wobbles, one stale debug line, a comment that names an actual variable. Looks like a Tuesday afternoon.
H-Code is a two-stage pipeline:
- Deterministic transformer β applies language-aware style rules (variable substitutions, spacing variance, comment injection, etc.)
- Optional LLM rewriter β sends the partially-styled code to a model with a strict prompt asking for one more pass of naturalism
flowchart LR
A["π₯ Input Code<br/>(language tagged)"] --> B["π² Seed with CRC32<br/>deterministic"]
B --> C["π§ Style Transformer<br/>inc/Humanizer.php"]
C --> D{"AI Enhance?"}
D -- "no" --> F["π€ Output"]
D -- "yes" --> E["π€ LLM Provider<br/>OpenAI Β· Anthropic Β· Pollinations"]
E --> G["π§Ή Output Sanitizer<br/>strip code fences"]
G --> F
F --> H["π Stats<br/>lines Β· chars Β· changes"]
style A fill:#0EA5E9,stroke:#0369A1,color:#fff
style F fill:#22C55E,stroke:#15803D,color:#fff
style E fill:#8B5CF6,stroke:#5B21B6,color:#fff
style C fill:#F59E0B,stroke:#B45309,color:#fff
| Stage | Strength | Weakness |
|---|---|---|
| Deterministic | Reproducible, fast, free, no API key | Pattern becomes obvious if used alone |
| LLM rewrite | Adds non-repeating, contextual noise | Costs tokens, requires a key, can drift semantically |
Used together, the deterministic stage primes the code with realistic scaffolding (variables, comments, formatting variance) so the LLM's pass focuses on subtler human fingerprints instead of structural rewrites.
Hcode/
βββ index.php # Web UI (single-page app shell)
βββ humanize.php # REST endpoint (POST /humanize.php)
β
βββ api/
β βββ ai-humanize.php # JSON proxy for AI engine
β βββ config.php # Live config read/write
β
βββ inc/
β βββ Humanizer.php # Core deterministic transformer (1014 LoC)
β βββ AIEngine.php # LLM provider router + prompt builder
β βββ Config.php # JSON config wrapper
β
βββ js/
β βββ app.js # UI logic, diff view, theme toggle
β
βββ css/
β βββ style.css # Vanilla CSS, no framework
β
βββ data/
βββ config.json # Provider, model, API keys
| Language | Key | Debug stmt | Comments | Whitespace |
|---|---|---|---|---|
| JavaScript | javascript |
console.* |
// /* */ |
insensitive |
| TypeScript | typescript |
console.* |
// /* */ |
insensitive |
| Python | python |
print() |
# ''' ''' |
significant |
| C++ | cpp |
std::cout |
// /* */ |
insensitive |
| Java | java |
System.out.* |
// /* */ |
insensitive |
| PHP | php |
var_dump |
// /* */ |
insensitive |
| C# | csharp |
Console.* |
// /* */ |
insensitive |
| Go | go |
fmt.* |
// /* */ |
insensitive |
| Rust | rust |
println! |
// /* */ |
insensitive |
| Ruby | ruby |
puts |
# =begin |
significant |
| Swift | swift |
print() |
// /* */ |
insensitive |
- PHP 8.1+ with
curlandjsonextensions - A web server (Apache, Nginx, or PHP's built-in server for dev)
- (Optional) An API key from OpenAI, Anthropic, or a Pollinations endpoint
# 1. Clone
git clone https://github.com/yourname/hcode.git
cd hcode
# 2. Make data writable
chmod 755 data/
chmod 644 data/config.json
# 3. Drop into your web root (or run the built-in server)
php -S localhost:8000Open http://localhost:8000 β paste code, pick a language, hit Humanize.
<VirtualHost *:80>
ServerName hcode.local
DocumentRoot /var/www/hcode
<Directory /var/www/hcode>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>server {
listen 80;
server_name hcode.local;
root /var/www/hcode;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}Edit data/config.json:
{
"provider": "openai",
"model": "gpt-4o",
"api_key": "sk-...",
"anthropic_key": "sk-ant-...",
"anthropic_model": "claude-sonnet-4-20250514",
"ai_enhance": true,
"ai_temperature": 0.8
}| Field | Default | Notes |
|---|---|---|
provider |
pollinations |
openai Β· anthropic Β· pollinations |
model |
provider default | e.g. gpt-4o, gpt-4o-mini, gpt-3.5-turbo |
api_key |
empty | Required for OpenAI |
anthropic_key |
empty | Required for Anthropic |
anthropic_model |
claude-sonnet-4-... |
Any current Claude model |
ai_enhance |
true |
Disable for offline / deterministic-only mode |
ai_temperature |
0.8 |
0 = robotic, 1+ = chaotic. Sweet spot: 0.7 β 0.9 |
π Security:
data/config.jsonmay contain API keys. Never commit it. Add it to.gitignoreand rotate keys if the file is ever exposed.
The UI is a single page (index.php + css/style.css + js/app.js).
It ships with:
- π¨ Dual-theme (light / dark, system-aware)
- π Three tabs β Input, Output, Diff
- βοΈ Live config panel β switch providers, tweak temperature
- π Real-time stats β line count delta, char count, change count
- π Re-roll β regenerate with a new seed
- π One-click copy of the output
- π Subtle noise overlay for that 2024 "designed by a designer" feel
Keyboard shortcuts:
| Key | Action |
|---|---|
Ctrl/β + Enter |
Run humanizer |
Ctrl/β + K |
Clear input |
Ctrl/β + D |
Toggle theme |
Transform code via the deterministic engine. No LLM call.
Request
{
"code": "function add(a, b) { return a + b; }",
"language": "javascript",
"intensity": 60
}Response
{
"success": true,
"original": "function add(a, b) { return a + b; }",
"humanized": "function add(a, b) {\n return (a + b)\n}",
"language": "javascript",
"intensity": 60,
"changes": 1,
"execution_time": "4.21ms",
"stats": {
"original_lines": 1,
"humanized_lines": 3,
"original_chars": 38,
"humanized_chars": 47
}
}Send code through the configured LLM provider.
Request
{
"code": "def greet(name):\n print(f'Hello {name}')",
"language": "python",
"intensity": 70
}Response
{
"success": true,
"humanized": "def greet(name):\n # quick greet\n print(f'Hello {name}') # works\n",
"model": "gpt-4o",
"tokens_used": 142
}Returns the current (sanitized) configuration β keys are stripped.
{
"provider": "anthropic",
"anthropic_model": "claude-sonnet-4-20250514",
"ai_enhance": true,
"ai_temperature": 0.85
}| Status | Meaning |
|---|---|
400 |
Missing field, invalid language, empty code, code > 100KB |
405 |
Wrong HTTP method |
500 |
Upstream LLM error or transformation failure |
curl -X POST http://localhost:8000/humanize.php \
-H "Content-Type: application/json" \
-d '{
"code": "const sum = (a, b) => a + b;",
"language": "javascript",
"intensity": 80
}'Use the deterministic engine in your own code β no HTTP, no LLM.
<?php
require_once __DIR__ . '/inc/Humanizer.php';
$h = new Humanizer(['version' => '2.0.0', 'max_code_length' => 100000]);
$out = $h->humanize(
code: 'def add(a, b):\n return a + b',
language: 'python',
intensity: 65
);
echo $out;Or with the LLM rewriter:
<?php
require_once __DIR__ . '/inc/AIEngine.php';
$engine = new AIEngine('openai');
$result = $engine->humanize($code, 'typescript', 75);
// $result = ['text' => '...', 'tokens' => 0]| Range | Profile | What you get |
|---|---|---|
10 β 30 |
Light | Subtle spacing variance, maybe one comment |
30 β 55 |
Moderate | Mixed naming, parens, 1-2 debug artifacts |
55 β 80 |
Strong | Multiple inconsistencies, dead vars, more comments |
80 β 100 |
Aggressive | "Tired developer at 2am" β messy but functional |
Intensity is a hint, not a hard target. The LLM is told: "be inconsistent β do not apply the same transformation to every line."
The deterministic stage applies a configurable subset of these techniques based on the chosen intensity:
Click to expand the full list (12 techniques)
| # | Technique | Description |
|---|---|---|
| 1 | Syntax equivalence | Swaps let β const β var, == β ===, ternary β if/else |
| 2 | Spacing variance | x+1 vs x + 1, sometimes trailing whitespace |
| 3 | String delimiters | Mixes '...' and "..." randomly |
| 4 | Naming drift | Replaces names with tmp, x, or longer context-fitting alternatives |
| 5 | Redundant parens | Adds parens around return values and conditions |
| 6 | Yoda conditions | if (null === x) instead of if (x === null) |
| 7 | Debug logs | Inserts forgotten console.log / print calls |
| 8 | Commented branches | // was using X, changed my mind style |
| 9 | Dead variables | Assignments that look like dev testing leftovers |
| 10 | Comment injection | Context-aware comments naming actual variables |
| 11 | Quote inconsistency | Same string literal written both ways in one file |
| 12 | Whitespace wobble | Indentation shifts Β±1 space on random lines |
β "Method not allowed"
You're sending GET to an endpoint that only accepts POST (or vice-versa).
Use:
curl -X POST http://localhost:8000/humanize.php ...β "Invalid language"
Check the Supported Languages table β keys are lowercase
and the C-family languages don't have dots (csharp, not c#).
β "Humanization failed"
Usually one of:
data/config.jsonnot writable βchmod 755 data/- API key missing β paste it in the settings cog
- Curl timeout β the LLM took too long; try
ai_enhance: false - Code contains a syntax error in the input β the LLM can't rewrite garbage
β "Code too long (max 100KB)"
The max_code_length in data/config.json defaults to 100,000 characters.
Bump it if you need to humanize large files β but the LLM will struggle past ~2K
tokens regardless.
β Output has weird markdown fences
The LLM sometimes wraps its output in ```js ... ``` even when told not to.
The sanitizer strips them, but if you see leftovers, the prompt has regressed β
check inc/AIEngine.php line ~47.
H-Code is a code style transformation tool. It changes how code looks, never what it does.
H-Code exists to explore how code style signals authorship, and to demonstrate stylistic transformations on text. The same techniques have legitimate uses in code obfuscation research, educational tooling, and red-team / blue-team exercises around AI-assisted developer workflows.
Don't use H-Code to:
- β Submit AI-generated work in academic courses that ban it
- β Violate employer policies on AI-assisted code
- β Misrepresent authorship in open-source contributions
- β Bypass code-origin audits in regulated environments
Do use H-Code to:
- β Learn how code style conveys authorship signals
- β Build detection / compliance tooling of your own
- β Stress-test your own AI detector
- β Refactor code style for a team standard
If your school, employer, or client has rules about disclosing AI assistance, follow those rules. H-Code is not a license to break them.
- π§ The LLM may hallucinate β always diff the output before trusting it
- π― AI detectors are an arms race β no transformation is permanently undetectable; results vary by detector and over time
- π Whitespace-sensitive languages (Python, Ruby) get fewer transformations because messing with indent breaks them
- π Same input = same output β the seed is
crc32($code). To get a new result, tweak a single character first - πΈ AI enhance costs tokens β a 500-line file β 2-4K input + 2-4K output
- Pluggable transformer pipeline (custom user-defined rules)
- Batch endpoint (array of code blocks in one request)
- CLI binary (
./hcode humanize file.py --lang python --intensity 70) - Webhook callback for long-running LLM jobs
- Detector round-trip score (run output through 3-5 detectors, report)
- VS Code extension
- Docker image
- Pluggable language configs (add Kotlin, Scala, Elixir)
Pull requests welcome. A few guidelines:
- Fork & branch from
main - Don't add new "undetectability" marketing claims to the README β the project is intentionally framed as a style transformation engine
- Keep
inc/Humanizer.phpdeterministic β anything stochastic should go through the seededmt_srandso the same input still produces the same output - Add a test in
tests/for any new transformation technique - Run
php -lon every changed.phpfile before pushing
# Lint
php -l inc/Humanizer.php
php -l inc/AIEngine.php
php -l humanize.php
# Smoke test (requires PHP built-in server running on :8000)
php tests/smoke.phpThe smoke test sends a known input through /humanize.php and asserts that:
- The response is valid JSON with
success: true - The output is different from the input
- The output is syntactically valid (parses in the target language)
MIT β do whatever you want, just keep the copyright notice.
If you fork and rebrand, please change the project name. It makes the "is this a fork or the original?" question easier to answer.
- The open-source maintainers of every language runtime H-Code targets
- The model providers (OpenAI, Anthropic, Pollinations) for keeping inference cheap
- Everyone who has ever left a
console.login production β you are the muse
Made with β‘ and probably too much caffeine.
If H-Code helped you learn something, a β is appreciated.