That's a reasoning model, but okay..
Code: Select all
; RSA 4096 Encryption/Decryption using Windows CNG in PureBasic
; Constants
#STATUS_SUCCESS = $00000000
#BCRYPT_RSAPUBLIC_BLOB = "RSAPUBLICBLOB"
#BCRYPT_PAD_PKCS1 = 2
; Prototypes for BCrypt functions
Prototype.l BCryptOpenAlgorithmProvider(phAlgorithm, pszAlgId.p-unicode, pszImplementation.p-unicode, dwFlags.l)
Prototype.l BCryptGenerateKeyPair(hAlgorithm, phKey, dwLength.l, dwFlags.l)
Prototype.l BCryptFinalizeKeyPair(hKey, dwFlags.l)
Prototype.l BCryptExportKey(hKey, hExportKey, pszBlobType.p-unicode, pbOutput, cbOutput.l, pcbResult, dwFlags.l)
Prototype.l BCryptImportKey(hAlgorithm, hImportKey, pszBlobType.p-unicode, phKey, pbKeyObject, cbKeyObject.l, pbInput, cbInput.l, dwFlags.l)
Prototype.l BCryptEncrypt(hKey, pbInput, cbInput.l, pPaddingInfo, pbIV, cbIV.l, pbOutput, cbOutput.l, pcbResult, dwFlags.l)
Prototype.l BCryptDecrypt(hKey, pbInput, cbInput.l, pPaddingInfo, pbIV, cbIV.l, pbOutput, cbOutput.l, pcbResult, dwFlags.l)
Prototype.l BCryptCloseAlgorithmProvider(hAlgorithm, dwFlags.l)
Prototype.l BCryptDestroyKey(hKey)
; Load BCrypt library and functions
Global hBCrypt = OpenLibrary(#PB_Any, "bcrypt.dll")
If Not hBCrypt
MessageRequester("Error", "Failed to load bcrypt.dll")
End
EndIf
Global BCryptOpenAlgorithmProvider.BCryptOpenAlgorithmProvider = GetFunction(hBCrypt, "BCryptOpenAlgorithmProvider")
Global BCryptGenerateKeyPair.BCryptGenerateKeyPair = GetFunction(hBCrypt, "BCryptGenerateKeyPair")
Global BCryptFinalizeKeyPair.BCryptFinalizeKeyPair = GetFunction(hBCrypt, "BCryptFinalizeKeyPair")
Global BCryptExportKey.BCryptExportKey = GetFunction(hBCrypt, "BCryptExportKey")
Global BCryptImportKey.BCryptImportKey = GetFunction(hBCrypt, "BCryptImportKey")
Global BCryptEncrypt.BCryptEncrypt = GetFunction(hBCrypt, "BCryptEncrypt")
Global BCryptDecrypt.BCryptDecrypt = GetFunction(hBCrypt, "BCryptDecrypt")
Global BCryptCloseAlgorithmProvider.BCryptCloseAlgorithmProvider = GetFunction(hBCrypt, "BCryptCloseAlgorithmProvider")
Global BCryptDestroyKey.BCryptDestroyKey = GetFunction(hBCrypt, "BCryptDestroyKey")
; Validate all functions loaded
If Not BCryptOpenAlgorithmProvider Or Not BCryptGenerateKeyPair Or Not BCryptFinalizeKeyPair Or
Not BCryptExportKey Or Not BCryptImportKey Or Not BCryptEncrypt Or Not BCryptDecrypt Or
Not BCryptCloseAlgorithmProvider Or Not BCryptDestroyKey
MessageRequester("Error", "Failed to load BCrypt functions")
End
EndIf
; Main process
Procedure Main()
; Initialize variables
Protected hAlg, hKey, hPublicKey, result.l, publicKeySize.l, *publicKeyBlob
Protected plainText$, plainSize.l, *plainData, encryptedSize.l, *encryptedData
Protected decryptedSize.l, *decryptedData, decryptedText$
; 1. Open RSA algorithm provider
result = BCryptOpenAlgorithmProvider(@hAlg, "RSA", #Null$, 0)
If result <> #STATUS_SUCCESS
MessageRequester("Error", "BCryptOpenAlgorithmProvider failed: " + Hex(result))
ProcedureReturn
EndIf
; 2. Generate 4096-bit RSA key pair
result = BCryptGenerateKeyPair(hAlg, @hKey, 4096, 0)
If result <> #STATUS_SUCCESS
MessageRequester("Error", "BCryptGenerateKeyPair failed: " + Hex(result))
BCryptCloseAlgorithmProvider(hAlg, 0)
ProcedureReturn
EndIf
; 3. Finalize key pair
result = BCryptFinalizeKeyPair(hKey, 0)
If result <> #STATUS_SUCCESS
MessageRequester("Error", "BCryptFinalizeKeyPair failed: " + Hex(result))
BCryptDestroyKey(hKey)
BCryptCloseAlgorithmProvider(hAlg, 0)
ProcedureReturn
EndIf
; 4. Export public key
result = BCryptExportKey(hKey, 0, #BCRYPT_RSAPUBLIC_BLOB, 0, 0, @publicKeySize, 0)
If result <> #STATUS_SUCCESS
MessageRequester("Error", "BCryptExportKey (size) failed: " + Hex(result))
BCryptDestroyKey(hKey)
BCryptCloseAlgorithmProvider(hAlg, 0)
ProcedureReturn
EndIf
*publicKeyBlob = AllocateMemory(publicKeySize)
result = BCryptExportKey(hKey, 0, #BCRYPT_RSAPUBLIC_BLOB, *publicKeyBlob, publicKeySize, @publicKeySize, 0)
If result <> #STATUS_SUCCESS
MessageRequester("Error", "BCryptExportKey failed: " + Hex(result))
FreeMemory(*publicKeyBlob)
BCryptDestroyKey(hKey)
BCryptCloseAlgorithmProvider(hAlg, 0)
ProcedureReturn
EndIf
; 5. Import public key
result = BCryptImportKey(hAlg, 0, #BCRYPT_RSAPUBLIC_BLOB, @hPublicKey, 0, 0, *publicKeyBlob, publicKeySize, 0)
FreeMemory(*publicKeyBlob)
If result <> #STATUS_SUCCESS
MessageRequester("Error", "BCryptImportKey failed: " + Hex(result))
BCryptDestroyKey(hKey)
BCryptCloseAlgorithmProvider(hAlg, 0)
ProcedureReturn
EndIf
; Prepare plaintext
plainText$ = "Hello World! This is a secret message."
plainSize = StringByteLength(plainText$, #PB_UTF8)
*plainData = AllocateMemory(plainSize)
PokeS(*plainData, plainText$, -1, #PB_UTF8)
; 6. Encrypt data
result = BCryptEncrypt(hPublicKey, *plainData, plainSize, 0, 0, 0, 0, 0, @encryptedSize, #BCRYPT_PAD_PKCS1)
If result <> #STATUS_SUCCESS
MessageRequester("Error", "BCryptEncrypt (size) failed: " + Hex(result))
FreeMemory(*plainData)
BCryptDestroyKey(hPublicKey)
BCryptDestroyKey(hKey)
BCryptCloseAlgorithmProvider(hAlg, 0)
ProcedureReturn
EndIf
*encryptedData = AllocateMemory(encryptedSize)
result = BCryptEncrypt(hPublicKey, *plainData, plainSize, 0, 0, 0, *encryptedData, encryptedSize, @encryptedSize, #BCRYPT_PAD_PKCS1)
FreeMemory(*plainData)
If result <> #STATUS_SUCCESS
MessageRequester("Error", "BCryptEncrypt failed: " + Hex(result))
FreeMemory(*encryptedData)
BCryptDestroyKey(hPublicKey)
BCryptDestroyKey(hKey)
BCryptCloseAlgorithmProvider(hAlg, 0)
ProcedureReturn
EndIf
; 7. Decrypt data
result = BCryptDecrypt(hKey, *encryptedData, encryptedSize, 0, 0, 0, 0, 0, @decryptedSize, #BCRYPT_PAD_PKCS1)
If result <> #STATUS_SUCCESS
MessageRequester("Error", "BCryptDecrypt (size) failed: " + Hex(result))
FreeMemory(*encryptedData)
BCryptDestroyKey(hPublicKey)
BCryptDestroyKey(hKey)
BCryptCloseAlgorithmProvider(hAlg, 0)
ProcedureReturn
EndIf
*decryptedData = AllocateMemory(decryptedSize)
result = BCryptDecrypt(hKey, *encryptedData, encryptedSize, 0, 0, 0, *decryptedData, decryptedSize, @decryptedSize, #BCRYPT_PAD_PKCS1)
FreeMemory(*encryptedData)
If result <> #STATUS_SUCCESS
MessageRequester("Error", "BCryptDecrypt failed: " + Hex(result))
FreeMemory(*decryptedData)
BCryptDestroyKey(hPublicKey)
BCryptDestroyKey(hKey)
BCryptCloseAlgorithmProvider(hAlg, 0)
ProcedureReturn
EndIf
; Show results
decryptedText$ = PeekS(*decryptedData, decryptedSize, #PB_UTF8)
MessageRequester("Success", "Decrypted text: " + decryptedText$)
; Cleanup
FreeMemory(*decryptedData)
BCryptDestroyKey(hPublicKey)
BCryptDestroyKey(hKey)
BCryptCloseAlgorithmProvider(hAlg, 0)
EndProcedure
Main()
CloseLibrary(hBCrypt)
Again, if you're going to grift on the internet make it take longer than five-minutes to see through by anyone with a web browser.. Literally anyone can open another browser-tab and immediately see all the models are unreliable, or just look at any standardized benchmarks; which Grok, OpenAI, DeepSeek, Anthropic themselves frequently share on blogs and social-media, and they -ALL- reflect exactly what I'm saying here; as do interviews with anyone from any of those companies everywhere..
In machine learning (ML), an **illusion** refers to a situation where a model perceives or generates patterns, features, or outputs that do not actually exist in the data or reality. This can occur due to various reasons, such as overfitting, biases in the training data, or limitations in the model's architecture. Illusions in ML are often unintended and can lead to incorrect or misleading results.
Here are some common examples of illusions in ML:
1. **Overfitting**:
- A model learns noise or irrelevant details in the training data, creating the illusion of patterns that do not generalize to new, unseen data.
- For example, a model might "memorize" random fluctuations in the training data and incorrectly assume they are meaningful.
2. **Adversarial Examples**:
- Small, carefully crafted perturbations in input data can create the illusion of a different class or output. For instance, an image classifier might misclassify a slightly modified image of a panda as a gibbon, even though the change is imperceptible to humans.
3. **Data Bias**:
- If the training data contains biases, the model may learn and perpetuate those biases, creating the illusion that the biased patterns are inherent to the problem. For example, a facial recognition system trained primarily on one demographic might perform poorly on others, creating the illusion that the system is universally accurate.
4. **Hallucinations in Generative Models**:
- Generative models, such as those used in text generation (e.g., GPT) or image synthesis (e.g., GANs), can produce outputs that appear realistic but are factually incorrect or nonsensical. For example, a text generator might produce a coherent-sounding paragraph with false information.
5. **Spurious Correlations**:
- Models might detect and rely on correlations in the training data that are coincidental or irrelevant, creating the illusion of a causal relationship. For example, a model might associate the presence of a certain object in an image with a specific label, even though the object is unrelated to the label.
6. **Optical Illusions in Computer Vision**:
- Models trained on visual data might misinterpret certain patterns or textures, similar to how humans perceive optical illusions. For instance, a model might misclassify an image due to unusual lighting or perspective.
### Addressing Illusions in ML
To mitigate illusions in ML, practitioners can:
- Use regularization techniques to prevent overfitting.
- Employ adversarial training to make models more robust to adversarial examples.
- Ensure diverse and representative training data to reduce biases.
- Validate models on independent datasets to test generalization.
- Use interpretability tools to understand model decisions and identify spurious patterns.
By addressing these issues, ML models can be made more reliable and less prone to creating or relying on illusions.
It might help to learn what a LSTM, RNN, or even MLP are before preaching AI branding hysteria and telling the public what it is and isn't..