# Enhancing Security of Online Interfaces: Adversarial Handwritten Arabic CAPTCHAs Generation
## 3 Methodology
### 4.
The softmax layer calculates the probability of each label using the input sequence and the RNN's current hidden state. 3. CTC Loss Function: The CTC loss function is utilized for computing the loss between the actual label sequence and the forecast probability distribution. The definition of the CTC loss function is as follows: \(L=(-log(P(y|x))\) where L is the loss and \(P(y|x)\) is the probability of finding the true label sequence y given the input sequence x. The CTC loss function is computed using dynamic programming, which allows the loss to be calculated efficiently even with long input sequences. Keras CTC was used to train a benchmark sequence recognition model. A stack of LSTM layers, a dense layer, and a CTC loss layer made up the model architecture. Until the model's performance was considered acceptable, it was trained on a sequence dataset. To generate adversarial examples, the Fast Gradient Sign Method (FGSM) can be applied to the CTC loss, computing the perturbation \(\delta=\epsilon*sign(\
abla_{x}L(x,y))\). FGSM is a simple and computationally inexpensive method for determining perturbations that increase a model's loss function. Given a test example, the FGSM determines the smallest perturbation required to change the model predictions. For each test example, the loss gradient was calculated with respect to the input and taking a step in the direction of the gradient's sign. The step size is a hyperparameter that determines the magnitude of the perturbation. Larger step sizes are more likely to affect model behavior, but they may introduce detectable noise. By feeding perturbed examples into the CTC model and monitoring whether the predictions change, the adversarial accuracy of the model was assessed. Additionally, the perturbations' qualitative impact on the inputs' discernible noise or distortions was calculated. We show the design of CTC in Algorithm 5. * Rationale for Selection. CTC was chosen for two reasons: 1. Temporal CAPTCHA Relevance: many CAPTCHAs use animated/text-scrolling designs; CTC's sequence alignment mirrors automated solvers' temporal reasoning. 2. Alignment Vulnerabilities: CTC's reliance on input-output alignment makes it susceptible to perturbations that shift temporal features (e.g., character onset/offset). * Key Insight: automated solvers over-rely on consistent character timing and spacing, which adversarial noise can disrupt. Per-Frame Noise: add dynamic, non-differentiable noise to individual frames to block gradient-based attacks. * Model Architecture:
* 3 bidirectional LSTM layers (256 units each),
* Optimizer (lr=0.001)
- \(\epsilon=0.05\) (normalized pixel range),
* Sequence perturbation budget: \(L\infty\leq 0.1\) per frame  
```
1:Input:
2:Input sequences \(X\)
3:Step sizes \(\alpha\)
4:True label sequence \(y\) Label sequences \(\pi\)
5:for all\(x\in X\)do
6:\(\pi\leftarrow\) Predict probability distribution using CTC model
7:\(L\leftarrow-\log(P(y|\pi))\) {Compute CTC loss}
8:\(\
abla L\leftarrow\frac{\delta L}{\delta x}\) {Compute loss gradient w.r.t \(x\)}
9:\(r\leftarrow\alpha\cdot(\
abla L)\) {Generate perturbation}
10:\(x^{\prime}\gets x+r\) {Create adversarial sequence}
11:endfor
12:Output: Adversarial image \(x^{\prime}\)
```  
**Algorithm 5** CTC Adversarial Generation.