# Code Smell 284 - Encrypted Functions

> TL;DR: Avoid obfuscated functions in your code.

This article is based on a [real social hacking disguised as a job interview](https://www.linkedin.com/posts/franco-aguilera-2583685a_the-code-challenge-scam-they-tried-to-hack-activity-7270114822950703107-K3DW/)

# Problems

- Hidden vulnerabilities

- Readability

- Testability

- Trust issues

- Bad Naming

# Solutions

1. Use clear names

2. Avoid obfuscation

3. Explain intent clearly

4. Review shared code

5. Don't trust code from unreliable sources

6. Avoid modification since it is a sign of [Premature Optimization](https://maximilianocontieri.com/code-smell-20-premature-optimization)

# Context

When you write functions with cryptic or obfuscated names, you make your code unreadable and untrustworthy. 

This pattern often hides malicious intent or makes debugging and collaboration unnecessarily hard. 

Cryptic code also frustrates team members and future maintainers, increasing technical debt and security risks.

Remember, hacking has a strong social component compared to what you see in Hollywood movies.

# Sample Code

## Wrong

<!-- [Gist Url](https://gist.github.com/mcsee/fc14884bd6d4a0b5d76e6b96eb30b10a) -->

```javascript
function _0xaexad(_0x12bfc3, _0x43a1e9) {
  return _0x12bfc3 ^ _0x43a1e9;
}

const result = _0xaexad(0x1a, 0x2f);
console.log(result);
```

## Right

<!-- [Gist Url](https://gist.github.com/mcsee/d3c4ca8ecbf71ab3a7ef157d87a5ac8d) -->

```javascript
function xorOperation(orValue1, orValue2) {
  return orValue1 ^ orValue2;
}

const result = xorOperation(26, 47);
console.log(result);
```

# Detection

[X] Automatic 

You can detect this smell by scanning your codebase for meaningless or obfuscated function names. 

Use linters or code analysis tools to flag short, cryptic, or randomly named functions. 

Manual code reviews can also help identify suspicious patterns.

# Tags

- Security

# Level

[X] Intermediate

# Why the Bijection Is Important 

Readable and meaningful names create a [one-to-one](https://maximilianocontieri.com/what-is-wrong-with-software) correspondence between the real-world concept and your code. 

Breaking this connection makes your program confusing and error-prone. 

# AI Generation

AI generators sometimes produce cryptic function names, especially when they optimize for brevity or imitate obfuscated patterns. 

# AI Detection

AI tools can detect and fix this smell when you ask them to refactor unclear function names or enforce coding standards. 

They can analyze your entire codebase and suggest meaningful replacements for obfuscated names.

## Try Them!

*Remember: AI Assistants make lots of mistakes*

| Without Proper Instructions    | With Specific Instructions |
| -------- | ------- |
| [ChatGPT](https://chat.openai.com/?q=Correct+and+explain+this+code%3A+%60%60%60javascript%0D%0Afunction+_0xaexad%28_0x12bfc3%2C+_0x43a1e9%29+%7B%0D%0A++return+_0x12bfc3+%5E+_0x43a1e9%3B%0D%0A%7D%0D%0A%0D%0Aconst+result+%3D+_0xaexad%280x1a%2C+0x2f%29%3B%0D%0Aconsole.log%28result%29%3B%0D%0A%60%60%60) | [ChatGPT](https://chat.openai.com/?q=remove+encryption%3A+%60%60%60javascript%0D%0Afunction+_0xaexad%28_0x12bfc3%2C+_0x43a1e9%29+%7B%0D%0A++return+_0x12bfc3+%5E+_0x43a1e9%3B%0D%0A%7D%0D%0A%0D%0Aconst+result+%3D+_0xaexad%280x1a%2C+0x2f%29%3B%0D%0Aconsole.log%28result%29%3B%0D%0A%60%60%60) |
| [Claude](https://claude.ai/new?q=Correct+and+explain+this+code%3A+%60%60%60javascript%0D%0Afunction+_0xaexad%28_0x12bfc3%2C+_0x43a1e9%29+%7B%0D%0A++return+_0x12bfc3+%5E+_0x43a1e9%3B%0D%0A%7D%0D%0A%0D%0Aconst+result+%3D+_0xaexad%280x1a%2C+0x2f%29%3B%0D%0Aconsole.log%28result%29%3B%0D%0A%60%60%60) | [Claude](https://claude.ai/new?q=remove+encryption%3A+%60%60%60javascript%0D%0Afunction+_0xaexad%28_0x12bfc3%2C+_0x43a1e9%29+%7B%0D%0A++return+_0x12bfc3+%5E+_0x43a1e9%3B%0D%0A%7D%0D%0A%0D%0Aconst+result+%3D+_0xaexad%280x1a%2C+0x2f%29%3B%0D%0Aconsole.log%28result%29%3B%0D%0A%60%60%60) |
| [Perplexity](https://perplexity.ai/?q=Correct+and+explain+this+code%3A+%60%60%60javascript%0D%0Afunction+_0xaexad%28_0x12bfc3%2C+_0x43a1e9%29+%7B%0D%0A++return+_0x12bfc3+%5E+_0x43a1e9%3B%0D%0A%7D%0D%0A%0D%0Aconst+result+%3D+_0xaexad%280x1a%2C+0x2f%29%3B%0D%0Aconsole.log%28result%29%3B%0D%0A%60%60%60) | [Perplexity](https://perplexity.ai/?q=remove+encryption%3A+%60%60%60javascript%0D%0Afunction+_0xaexad%28_0x12bfc3%2C+_0x43a1e9%29+%7B%0D%0A++return+_0x12bfc3+%5E+_0x43a1e9%3B%0D%0A%7D%0D%0A%0D%0Aconst+result+%3D+_0xaexad%280x1a%2C+0x2f%29%3B%0D%0Aconsole.log%28result%29%3B%0D%0A%60%60%60) |
| [Copilot](https://www.bing.com/chat?showconv=1&sendquery=1&q=Correct+and+explain+this+code%3A+%60%60%60javascript%0D%0Afunction+_0xaexad%28_0x12bfc3%2C+_0x43a1e9%29+%7B%0D%0A++return+_0x12bfc3+%5E+_0x43a1e9%3B%0D%0A%7D%0D%0A%0D%0Aconst+result+%3D+_0xaexad%280x1a%2C+0x2f%29%3B%0D%0Aconsole.log%28result%29%3B%0D%0A%60%60%60) | [Copilot](https://www.bing.com/chat?showconv=1&sendquery=1&q=remove+encryption%3A+%60%60%60javascript%0D%0Afunction+_0xaexad%28_0x12bfc3%2C+_0x43a1e9%29+%7B%0D%0A++return+_0x12bfc3+%5E+_0x43a1e9%3B%0D%0A%7D%0D%0A%0D%0Aconst+result+%3D+_0xaexad%280x1a%2C+0x2f%29%3B%0D%0Aconsole.log%28result%29%3B%0D%0A%60%60%60) |
| [Gemini](https://gemini.google.com/?q=Correct+and+explain+this+code%3A+%60%60%60javascript%0D%0Afunction+_0xaexad%28_0x12bfc3%2C+_0x43a1e9%29+%7B%0D%0A++return+_0x12bfc3+%5E+_0x43a1e9%3B%0D%0A%7D%0D%0A%0D%0Aconst+result+%3D+_0xaexad%280x1a%2C+0x2f%29%3B%0D%0Aconsole.log%28result%29%3B%0D%0A%60%60%60) | [Gemini](https://gemini.google.com/?q=remove+encryption%3A+%60%60%60javascript%0D%0Afunction+_0xaexad%28_0x12bfc3%2C+_0x43a1e9%29+%7B%0D%0A++return+_0x12bfc3+%5E+_0x43a1e9%3B%0D%0A%7D%0D%0A%0D%0Aconst+result+%3D+_0xaexad%280x1a%2C+0x2f%29%3B%0D%0Aconsole.log%28result%29%3B%0D%0A%60%60%60) | 

# Conclusion

Avoid obfuscating your function names. 

Write code that communicates your intent. 

When you prioritize readability, you make your software easier to understand, debug, and maintain. 

Cryptic code might look [clever](https://maximilianocontieri.com/code-smell-06-too-clever-programmer), but it adds unnecessary complexity.

# Relations

%[https://maximilianocontieri.com/code-smell-138-packages-dependency]

%[https://maximilianocontieri.com/code-smell-215-deserializing-object-vulnerability]

%[https://maximilianocontieri.com/code-smell-06-too-clever-programmer]

%[https://maximilianocontieri.com/code-smell-20-premature-optimization]

# More Info

%[https://www.linkedin.com/posts/franco-aguilera-2583685a_the-code-challenge-scam-they-tried-to-hack-activity-7270114822950703107-K3DW/]

# Disclaimer

Code Smells are my [opinion](https://maximilianocontieri.com/i-wrote-more-than-90-articles-on-2021-here-is-what-i-learned).

# Credits

Photo by [Nikita Pavlov](https://unsplash.com/@pavme) on [Unsplash](https://unsplash.com/photos/a-person-with-a-mask-2RBo6q8bBko)      
  
* * *

> The strength of a cryptographic system depends entirely on the strength of its weakest component. 

_Bruce Schneier_
 
%[https://maximilianocontieri.com/software-engineering-great-quotes]

* * *

This article is part of the CodeSmell Series.

%[https://maximilianocontieri.com/how-to-find-the-stinky-parts-of-your-code]
