#!/bin/bash

# Copyright (c) 2026 Bible Code Lab
# You may share and modify this code only for the purpose of improvement.
# Modifications intended to alter, bias, or manipulate computational results,
# or to introduce malicious behavior, are strictly prohibited.
# This software is provided "as is", without warranty of any kind.
# 
# SCRIPT NAME:  isaiah-53-esl.sh
#
# DESCRIPTION:  Test the two ELS codes of Isaiah 53:8-54:1 using regular 
#               expressions. It verifies this code against two versions of the 
#               Hebrew Bible:
#               - Miqra According to the Masorah (MAM): only 1 ELS found
#               - Leningrad Codex: both ELS found
#
# AUTHOR:       Bible Code Lab
#
# DATE:         2025-11-24
#
# VERSION:      1.0
#
# TESTED ON: 
#               - 6.12.63+deb13-amd64 GNU/Linux
#               - GNU sed v4.9
#               - GNU wget v1.25.0
#
# USAGE:        ./isaiah-53-esl.sh
#
#               If the patterns matches (the ELS is found), the sed command 
#               should print the Hebrew letters it is compossed of. Otherwise, 
#               it won't print anything.
#
# NOTES:        For more info go to:
#               https://beholdthestone.com/archives/770
# 

ISAIAH_MAM_FILENAME="isaiah-mam.csv";
ISAIAH_LENINGRAD_FILENAME="isaiah-leningrad.json";
SUFFIX="clean.txt"

function testELS() {
  FILE_CLEAN_NAME="$1-$SUFFIX"

  # Removes every chapter that is not in the Hebrew classic alphabet
  grep -oP '[\x{05D0}-\x{05EA}]+' $1 | tr -d '\n' > $FILE_CLEAN_NAME
  
  printf "Jesus is my name: "
  sed -E -n "s/^.+(\xD7\x99).{19}(\xD7\x9E).{19}(\xD7\xA9).{19}(\xD7\xA2).{19}(\xD7\x95).{19}(\xD7\xA9).{19}(\xD7\x99).+$/\7\6\5\4\3\2\1/p" $FILE_CLEAN_NAME
  printf "\n"

  printf "I was crucified: "
  sed -E -n "s/^.+(\xD7\x9F).{51}(\xD7\xA5).{51}(\xD7\x9C).{51}(\xD7\x91).{51}(\xD7\xAA).{51}(\xD7\x99).+$/\1\2\3\4\5\6/p" $FILE_CLEAN_NAME
  printf "\n"
}

wget -O $ISAIAH_MAM_FILENAME https://github.com/TorahBibleCodes/TorahBibleCodes/blob/master/texts/text_MAM_12isaiah.csv
printf "Matching ELS in Miqra according to the Masorah\n"
testELS $ISAIAH_MAM_FILENAME
printf "\n"

wget -O $ISAIAH_LENINGRAD_FILENAME https://github.com/TorahBibleCodes/TorahBibleCodes/blob/master/texts/text_leningrad_12isaiah.json
printf "Matching ELS in Leningrad Codex\n"
testELS $ISAIAH_LENINGRAD_FILENAME

