Author Topic: Daily Psalms via a Python Script and a Demo of Encryption and Decryption ...  (Read 1166 times)

Offline David

  • Hero Member
  • *****
  • Posts: 647
    • View Profile
Here is the Python script that extracts daily 5 Psalms ... Psalm 1 to 5 for day 1 of each month, 6 to 10 for day 2 of the month, 11 to 15 for day 3 ... etc...

Save this as a text file as: DailyPsalms.py file in a folder ...

and also save the text file it needs ... see it on the next page ... save that text in the same folder as: 1To150PsalmsFixed.txt


Code: [Select]
#DailyPsalms.py
#2024-02-15

from datetime import date
from sys import exit

fNameFixed = "1To150PsalmsFixed.txt"
try:
    with open(fNameFixed) as f:
        lines = f.readlines() # get lines into Python list called lines
except:
    print("Can't find file", fNameFixed, "... ")
    input("PRESS Enter key to exit ... ")
    exit()
   
#get current date
now = date.today()
day = now.day

print("Today is: {:4d}-{:02d}-{:02d}".format(now.year, now.month, day))
if day == 31: # there are only 150 Psalms
    day = 30
end = day*5
beg = end-4

these = [] # get a Python list of these ...
for x in range(beg, end+1):
    these.append( '(Ps ' + str(x) + ':' )

verses = [] # get todays 5 verses into Python list of verses
for line in lines:
    for text in these:
        if text in line:
            verses.append(line)
           
for line in verses:
    print()
    count = 0
    for ch in line:
        count += 1
        if count <= 40:
            if count == 1 and ch == ' ':
                count = 0
            else:
                print( ch, end = '' )
        else: #count here is > 40
            print(ch, end = '')
            if ch in " .,?!":
                print()
                count = 0
            if ch == '\n':
                count = 0
                   
input("\nPress 'Enter' to quit ... " )

« Last Edit: March 14, 2024, 11:02:21 PM by David »

Offline David

  • Hero Member
  • *****
  • Posts: 647
    • View Profile
Ok ... here is the text you need for the running Python code above ...

OOPs!!! TOO long for this page ... go to site at link below and copy text  there .... and save as:

1To150PsalmsFixed.txt

https://docs.google.com/document/d/1pCrJVR87k5GR5xhoaeEEsiivNotIU5MDp83_tvWF3bU/edit?usp=sharing

or

https://docs.google.com/document/d/e/2PACX-1vT2a9UqM3fx5MKPNiQIU5b35UYpH6otGQpU3DdBHugt0y6159eJaxuIUmIDTwKjIz1swQ8X4Sqmzyvl/pub

The first part of this file so that you might see how it is structured ...

Code: [Select]
Blessed [is] the man that walketh not in the counsel of the ungodly, nor standeth in the way of sinners, nor sitteth in the seat of the scornful. (Ps 1:1 AV)
But his delight [is] in the law of the LORD; and in his law doth he meditate day and night. (Ps 1:2 AV)
And he shall be like a tree planted by the rivers of water, that bringeth forth his fruit in his season; his leaf also shall not wither; and whatsoever he doeth shall prosper. (Ps 1:3 AV)
The ungodly [are] not so: but [are] like the chaff which the wind driveth away. (Ps 1:4 AV)
Therefore the ungodly shall not stand in the judgment, nor sinners in the congregation of the righteous. (Ps 1:5 AV)
For the LORD knoweth the way of the righteous: but the way of the ungodly shall perish. (Ps 1:6 AV)
Why do the heathen rage, and the people imagine a vain thing? (Ps 2:1 AV)
The kings of the earth set themselves, and the rulers take counsel together, against the LORD, and against his anointed, [saying], (Ps 2:2 AV)
Let us break their bands asunder, and cast away their cords from us. (Ps 2:3 AV)
He that sitteth in the heavens shall laugh: the Lord shall have them in derision. (Ps 2:4 AV)
Then shall he speak unto them in his wrath, and vex them in his sore displeasure. (Ps 2:5 AV)
Yet have I set my king upon my holy hill of Zion. (Ps 2:6 AV)
I will declare the decree: the LORD hath said unto me, Thou [art] my Son; this day have I begotten thee. (Ps 2:7 AV)
Ask of me, and I shall give [thee] the heathen [for] thine inheritance, and the uttermost parts of the earth [for] thy possession. (Ps 2:8 AV)
Thou shalt break them with a rod of iron; thou shalt dash them in pieces like a potter's vessel. (Ps 2:9 AV)
Be wise now therefore, O ye kings: be instructed, ye judges of the earth. (Ps 2:10 AV)
Serve the LORD with fear, and rejoice with trembling. (Ps 2:11 AV)
Kiss the Son, lest he be angry, and ye perish [from] the way, when his wrath is kindled but a little. Blessed [are] all they that put their trust in him. (Ps 2:12 AV)
A Psalm of David, when he fled from Absalom his son. LORD, how are they increased that trouble me! many [are] they that rise up against me. (Ps 3:1 AV)
Many [there be] which say of my soul, [There is] no help for him in God. Selah. (Ps 3:2 AV)
But thou, O LORD, [art] a shield for me; my glory, and the lifter up of mine head. (Ps 3:3 AV)
I cried unto the LORD with my voice, and he heard me out of his holy hill. Selah. (Ps 3:4 AV)
I laid me down and slept; I awaked; for the LORD sustained me. (Ps 3:5 AV)
I will not be afraid of ten thousands of people, that have set [themselves] against me round about. (Ps 3:6 AV)
Arise, O LORD; save me, O my God: for thou hast smitten all mine enemies [upon] the cheek bone; thou hast broken the teeth of the ungodly. (Ps 3:7 AV)
Salvation [belongeth] unto the LORD: thy blessing [is] upon thy people. Selah. (Ps 3:8 AV)
To the chief Musician on Neginoth, A Psalm of David. Hear me when I call, O God of my righteousness: thou hast enlarged me [when I was] in distress; have mercy upon me, and hear my prayer. (Ps 4:1 AV)
O ye sons of men, how long [will ye turn] my glory into shame? [how long] will ye love vanity, [and] seek after leasing? Selah. (Ps 4:2 AV)
But know that the LORD hath set apart him that is godly for himself: the LORD will hear when I call unto him. (Ps 4:3 AV)
Stand in awe, and sin not: commune with your own heart upon your bed, and be still. Selah. (Ps 4:4 AV)
Offer the sacrifices of righteousness, and put your trust in the LORD. (Ps 4:5 AV)
[There be] many that say, Who will shew us [any] good? LORD, lift thou up the light of thy countenance upon us. (Ps 4:6 AV)
Thou hast put gladness in my heart, more than in the time [that] their corn and their wine increased. (Ps 4:7 AV)
I will both lay me down in peace, and sleep: for thou, LORD, only makest me dwell in safety. (Ps 4:8 AV)
To the chief Musician upon Nehiloth, A Psalm of David. Give ear to my words, O LORD, consider my meditation. (Ps 5:1 AV)
Hearken unto the voice of my cry, my King, and my God: for unto thee will I pray. (Ps 5:2 AV)
My voice shalt thou hear in the morning, O LORD; in the morning will I direct [my prayer] unto thee, and will look up. (Ps 5:3 AV)
For thou [art] not a God that hath pleasure in wickedness: neither shall evil dwell with thee. (Ps 5:4 AV)
The foolish shall not stand in thy sight: thou hatest all workers of iniquity. (Ps 5:5 AV)
Thou shalt destroy them that speak leasing: the LORD will abhor the bloody and deceitful man. (Ps 5:6 AV)
But as for me, I will come [into] thy house in the multitude of thy mercy: [and] in thy fear will I worship toward thy holy temple. (Ps 5:7 AV)
Lead me, O LORD, in thy righteousness because of mine enemies; make thy way straight before my face. (Ps 5:8 AV)
For [there is] no faithfulness in their mouth; their inward part [is] very wickedness; their throat [is] an open sepulchre; they flatter with their tongue. (Ps 5:9 AV)
Destroy thou them, O God; let them fall by their own counsels; cast them out in the multitude of their transgressions; for they have rebelled against thee. (Ps 5:10 AV)
But let all those that put their trust in thee rejoice: let them ever shout for joy, because thou defendest them: let them also that love thy name be joyful in thee. (Ps 5:11 AV)
For thou, LORD, wilt bless the righteous; with favour wilt thou compass him as [with] a shield. (Ps 5:12 AV)
To the chief Musician on Neginoth upon Sheminith, A Psalm of David. O LORD, rebuke me not in thine anger, neither chasten me in thy hot displeasure. (Ps 6:1 AV)
Have mercy upon me, O LORD; for I [am] weak: O LORD, heal me; for my bones are vexed. (Ps 6:2 AV)
My soul is also sore vexed: but thou, O LORD, how long? (Ps 6:3 AV)
Return, O LORD, deliver my soul: oh save me for thy mercies' sake. (Ps 6:4 AV)
For in death [there is] no remembrance of thee: in the grave who shall give thee thanks? (Ps 6:5 AV)
I am weary with my groaning; all the night make I my bed to swim; I water my couch with my tears. (Ps 6:6 AV)
Mine eye is consumed because of grief; it waxeth old because of all mine enemies. (Ps 6:7 AV)
Depart from me, all ye workers of iniquity; for the LORD hath heard the voice of my weeping. (Ps 6:8 AV)
The LORD hath heard my supplication; the LORD will receive my prayer. (Ps 6:9 AV)
Let all mine enemies be ashamed and sore vexed: let them return [and] be ashamed suddenly. (Ps 6:10 AV)
Shiggaion of David, which he sang unto the LORD, concerning the words of Cush the Benjamite. O LORD my God, in thee do I put my trust: save me from all them that persecute me, and deliver me: (Ps 7:1 AV)
Lest he tear my soul like a lion, rending [it] in pieces, while [there is] none to deliver. (Ps 7:2 AV)
O LORD my God, if I have done this; if there be iniquity in my hands; (Ps 7:3 AV)
If I have rewarded evil unto him that was at peace with me; (yea, I have delivered him that without cause is mine enemy:) (Ps 7:4 AV)
Let the enemy persecute my soul, and take [it]; yea, let him tread down my life upon the earth, and lay mine honour in the dust. Selah. (Ps 7:5 AV)
Arise, O LORD, in thine anger, lift up thyself because of the rage of mine enemies: and awake for me [to] the judgment [that] thou hast commanded. (Ps 7:6 AV)
So shall the congregation of the people compass thee about: for their sakes therefore return thou on high. (Ps 7:7 AV)
The LORD shall judge the people: judge me, O LORD, according to my righteousness, and according to mine integrity [that is] in me. (Ps 7:8 AV)
Oh let the wickedness of the wicked come to an end; but establish the just: for the righteous God trieth the hearts and reins. (Ps 7:9 AV)
My defence [is] of God, which saveth the upright in heart. (Ps 7:10 AV)
God judgeth the righteous, and God is angry [with the wicked] every day. (Ps 7:11 AV)
If he turn not, he will whet his sword; he hath bent his bow, and made it ready. (Ps 7:12 AV)
He hath also prepared for him the instruments of death; he ordaineth his arrows against the persecutors. (Ps 7:13 AV)
Behold, he travaileth with iniquity, and hath conceived mischief, and brought forth falsehood. (Ps 7:14 AV)
He made a pit, and digged it, and is fallen into the ditch [which] he made. (Ps 7:15 AV)
His mischief shall return upon his own head, and his violent dealing shall come down upon his own pate. (Ps 7:16 AV)
I will praise the LORD according to his righteousness: and will sing praise to the name of the LORD most high. (Ps 7:17 AV)
To the chief Musician upon Gittith, A Psalm of David. O LORD our Lord, how excellent [is] thy name in all the earth! who hast set thy glory above the heavens. (Ps 8:1 AV)
Out of the mouth of babes and sucklings hast thou ordained strength because of thine enemies, that thou mightest still the enemy and the avenger. (Ps 8:2 AV)
When I consider thy heavens, the work of thy fingers, the moon and the stars, which thou hast ordained; (Ps 8:3 AV)
What is man, that thou art mindful of him? and the son of man, that thou visitest him? (Ps 8:4 AV)
For thou hast made him a little lower than the angels, and hast crowned him with glory and honour. (Ps 8:5 AV)
Thou madest him to have dominion over the works of thy hands; thou hast put all [things] under his feet: (Ps 8:6 AV)
All sheep and oxen, yea, and the beasts of the field; (Ps 8:7 AV)
The fowl of the air, and the fish of the sea, [and whatsoever] passeth through the paths of the seas. (Ps 8:8 AV)
O LORD our Lord, how excellent [is] thy name in all the earth! (Ps 8:9 AV)
To the chief Musician upon Muthlabben, A Psalm of David. I will praise [thee], O LORD, with my whole heart; I will shew forth all thy marvellous works. (Ps 9:1 AV)
I will be glad and rejoice in thee: I will sing praise to thy name, O thou most High. (Ps 9:2 AV)
When mine enemies are turned back, they shall fall and perish at thy presence. (Ps 9:3 AV)
For thou hast maintained my right and my cause; thou satest in the throne judging right. (Ps 9:4 AV)
Thou hast rebuked the heathen, thou hast destroyed the wicked, thou hast put out their name for ever and ever. (Ps 9:5 AV)
O thou enemy, destructions are come to a perpetual end: and thou hast destroyed cities; their memorial is perished with them. (Ps 9:6 AV)
But the LORD shall endure for ever: he hath prepared his throne for judgment. (Ps 9:7 AV)
And he shall judge the world in righteousness, he shall minister judgment to the people in uprightness. (Ps 9:8 AV)
The LORD also will be a refuge for the oppressed, a refuge in times of trouble. (Ps 9:9 AV)
And they that know thy name will put their trust in thee: for thou, LORD, hast not forsaken them that seek thee. (Ps 9:10 AV)
Sing praises to the LORD, which dwelleth in Zion: declare among the people his doings. (Ps 9:11 AV)
When he maketh inquisition for blood, he remembereth them: he forgetteth not the cry of the humble. (Ps 9:12 AV)
Have mercy upon me, O LORD; consider my trouble [which I suffer] of them that hate me, thou that liftest me up from the gates of death: (Ps 9:13 AV)
That I may shew forth all thy praise in the gates of the daughter of Zion: I will rejoice in thy salvation. (Ps 9:14 AV)
The heathen are sunk down in the pit [that] they made: in the net which they hid is their own foot taken. (Ps 9:15 AV)
The LORD is known [by] the judgment [which] he executeth: the wicked is snared in the work of his own hands. Higgaion. Selah. (Ps 9:16 AV)
The wicked shall be turned into hell, [and] all the nations that forget God. (Ps 9:17 AV)
For the needy shall not alway be forgotten: the expectation of the poor shall [not] perish for ever. (Ps 9:18 AV)
Arise, O LORD; let not man prevail: let the heathen be judged in thy sight. (Ps 9:19 AV)
Put them in fear, O LORD: [that] the nations may know themselves [to be but] men. Selah. (Ps 9:20 AV)
« Last Edit: February 27, 2024, 10:51:33 PM by David »

Offline David

  • Hero Member
  • *****
  • Posts: 647
    • View Profile
Now place this .bat file in same folder ...

Code: [Select]
:: RunItDailyVerses.bat
::

@ECHO OFF
echo PRESS Enter key to see today's texts in text editor Notepad...

DailyPsalms.py > holdIt.txt
notepad holdIt.txt
« Last Edit: February 18, 2024, 06:43:34 AM by David »

Offline David

  • Hero Member
  • *****
  • Posts: 647
    • View Profile
Scramble it ...


Code: [Select]
# holdIttoholdIt2.py

shifts = '31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679'
size = len(shifts)

with open("holdIt.txt") as fin:
    with open("holdIt2.txt", "w") as fin2:
        i = 0
        for item in fin:
            for c in item:
                if c.islower():
                    fin2.write( chr((ord(c) - ord('a') + int(shifts[i%size]) ) % 26 + ord('a')) )
                elif c.isupper():
                    fin2.write( chr((ord(c) - ord('A') + int(shifts[i%size]) ) % 26 + ord('A')) )
                else:
                    fin2.write( c )
                i += 1
                   
input("Done writing holdIt to holdIt2.txt... ")
« Last Edit: February 18, 2024, 07:03:19 AM by David »

Offline David

  • Hero Member
  • *****
  • Posts: 647
    • View Profile
Unscramble it ...

Code: [Select]
# holdIt2ToholdIt3.py

shifts = '31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679'

size = len(shifts)

with open("holdIt2.txt") as fin:
    with open("holdIt3.txt", "w") as fin2:
        i = 0
        for item in fin:
            for c in item:
                if c.islower():
                    fin2.write( chr((ord(c) - ord('a') - int(shifts[i%size]) ) % 26 + ord('a')) )
                elif c.isupper():
                    fin2.write( chr((ord(c) - ord('A') - int(shifts[i%size]) ) % 26 + ord('A')) )
                else:
                    fin2.write( c )
                i += 1
                   
input("Done writing holdIt2 to holdIt3.txt... ")
« Last Edit: February 18, 2024, 07:04:42 AM by David »

Offline David

  • Hero Member
  • *****
  • Posts: 647
    • View Profile
Make and run this batch file to automate above ...


Code: [Select]
:: RunItScrambleUnscrambleVerses.bat
::

@ECHO OFF
echo PRESS Enter key to begin ...

notepad holdIt.txt

holdIttoholdit2.py
notepad holdIt2.txt

holdIt2toholdit3.py
notepad holdIt3.txt

« Last Edit: February 18, 2024, 07:14:13 AM by David »

Offline David

  • Hero Member
  • *****
  • Posts: 647
    • View Profile
Or ... can use this more 'classical and memory efficient way' to extract the 5 Psalms for each day ...

Code: [Select]
# 5PsalmsForEachDay.py
# this version: 2024-03-14

from datetime import date
from sys import exit

#get current date
now = date.today()
day = now.day

print("Today is: {:4d}-{:02d}-{:02d}".format(now.year, now.month, day))
if day == 31: # there are only 30*5 = 150 Psalms
    day = 30  # for day 31 repeat day 30 Psalms

# get delimits to start and end of today's 5 verses ...   
end = day*5
beg = end-4
startAtStr = '(Ps ' + str(beg) + ':'
endAfterStr = '(Ps ' + str(end) + ':'

verses = [] # construct an empty list
fNameFixed = "1To150PsalmsFixed.txt"
try:
    with open(fNameFixed) as f:
        while (line := f.readline()) and startAtStr not in line:
            pass
           
        # stopped avove at first line of first chapter for today so ...
        verses.append(line)
           
        # now get all these also ...
        while (line := f.readline()) and endAfterStr not in line:
            verses.append(line)
               
        # above stopped at this first line of last chapter for today
        # so get ...
        verses.append(line)

        # now get rest of lines/verses in the last chapter ...
        while (line := f.readline()) and endAfterStr in line:
            verses.append(line)
           
        # when reach here, at end of 5th verse or reached file end         
except:
    print("Can't find file", fNameFixed, \
          " (or some other unexpected error) ... ")
    input("PRESS Enter key to exit ... ")
    exit()

# ok ... now can output the 5 verses formatted to NOT
# much more than 40 charactters per line         
for line in verses:
    print()
    count = 0
    for ch in line:
        count += 1
        if count <= 40:
            if count == 1 and ch == ' ':
                count = 0
            else:
                print( ch, end = '' )
        else: #count here is > 40
            print(ch, end = '')
            if ch in " .,?!":
                print()
                count = 0
            if ch == '\n':
                count = 0
                   
input("\nPress 'Enter' to quit ... " )
« Last Edit: March 14, 2024, 08:52:04 PM by David »

Offline David

  • Hero Member
  • *****
  • Posts: 647
    • View Profile
Or ... can encode and decode like this:

encode.py
Code: [Select]
# encode.py
# this version: 20240312

shifts = '31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679'
size = len(shifts)

with open("holdIt.txt", 'br') as fin:
    with open("holdIt2.txt", "bw") as fout:
        i = 0
        bites = fin.read()
        for bite in bites:
            fout.write( int.to_bytes(bite + int(shifts[i%size]) % 256) )
            i += 1

    print(i, 'bytes encoded ... ')
                   
input("Done writing holdIt to holdIt2.txt... ")


decode.py
Code: [Select]
# decode.py
# this version: 20240312

shifts = '31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679'

size = len(shifts)

with open("holdIt2.txt", 'br') as fin:
    with open("holdIt3.txt", 'bw') as fout:
        i = 0
        bites = fin.read()
##        print('type(bites) =', type(bites))
##        print(bites[0], bites[:10])
        for bite in bites:
            fout.write( int.to_bytes(bite - int(shifts[i%size]) % 256) )
            i += 1
    print(i, 'bytes decoded ... ')
   
input("Done writing holdIt2 to holdIt3.txt... ")