Best Python code snippet using autotest_python
mp3Stego.py
Source: mp3Stego.py
1import mp3Parser2import math3isModifiedBool = False4sizeOfMessage = 05def signature(isModifiedNum, size):6 mp3Parser.seekStart()7 _embed(1) # start num8 if(size > 255):9 loop = math.floor(size / 255)10 _embed(loop) # to see how many times extract to calculate size of embedded message11 _embed(isModifiedNum) # is modified flag12 _embed(1) # to set flag whether size is bigger than 25513 _embed(size % 255)14 else:15 _embed(size) # to see how many times extract to calculate size of embedded message loop buradan geliyor16 _embed(isModifiedNum) # is modified flag17 _embed(0) # zero means the size of message is equal to 255 or smaller than 25518def _getSignature():19 global sizeOfMessage20 isModifiedBool = False21 mp3Parser.seekStart()22 _extract()23 mp3Parser.nextFrame()24 loop = _extract()25 mp3Parser.nextFrame()26 ismodifiednum = _extract()27 mp3Parser.nextFrame()28 flag = _extract()29 if((ismodifiednum == 23) | (ismodifiednum == 33)):30 isModifiedBool = True31 if(flag == 1):32 mp3Parser.nextFrame()33 mod = _extract()34 sizeOfMessage = mod + loop*25535 else:36 sizeOfMessage = loop37 return sizeOfMessage, isModifiedBool, ismodifiednum38def _embed(payload):39 array = 0x0F40 for i in range(2):41 header = mp3Parser.getFrameHeader()42 header[1] = header[1] & 0xF043 a = payload & array44 header[1] = header[1] | a45 payload = payload >> 446 mp3Parser.setFrameHeader(header)47 mp3Parser.nextFrame()48def _extract():49 topla = 0x0F50 header = mp3Parser.getFrameHeader()51 topla = topla & header[1]52 mp3Parser.nextFrame()53 header = mp3Parser.getFrameHeader()54 header[1] = header[1] << 455 binary = format(header[1], "08b")56 header[1] = int(binary[-8:], 2)57 topla = topla | header[1]58 return topla59def _countFrames():60 mp3Parser.seekStart()61 size, isModifiedBool, ismodifiednumber = _getSignature()62 print(isModifiedBool)63 print(ismodifiednumber)64 mp3Parser.nextFrame()65 frames = 066 while mp3Parser.hasNext():67 frames += 168 mp3Parser.nextFrame()69 if(isModifiedBool):70 frames -= size71 return frames72def calculateEmptyBytes():73 frameCount = _countFrames()74 print(frameCount)75 frameCount = math.floor(frameCount/2)76 kiloByte = frameCount / 100077 return kiloByte78def isModified():79 mp3Parser.seekStart()80 frames, isModifiedBool, ismodifiednumber= _getSignature()81 mp3Parser.nextFrame()82 return frames,isModifiedBool83def embedText(isModifiedNum, message):84 mp3Parser.seekStart()85 signature(isModifiedNum, len(message))86 for i in message:87 _embed(i)88def extractText():89 mp3Parser.seekStart()90 enc = []91 frames, isModifiedBool, ismodifiednum = _getSignature()92 mp3Parser.nextFrame()93 i = 094 while i < frames:95 enc.append(_extract())96 mp3Parser.nextFrame()97 i += 198 return enc, ismodifiednum99def yazdir(newfilename):100 with open(newfilename, 'wb') as writer:...
UrlSignature.py
Source: UrlSignature.py
1'''2Created on 2. feb. 201234@author: pcn5'''6import hashlib7import time89class UrlSignature(object):10 def __init__(self, passwd = "GoGoGrillazEatingBananasFtw"):11 self._passwd = passwd12 self._offset = 01314 def setPasswd(self, passwd):15 self._passwd = passwd1617 def calculateOffset(self, serverTime):18 self._offset = serverTime - time.time()1920#GoGoGrillazEatingBananasFtw??imageThumb=0C&time=0.00&sigTime=1328193128.45 -> 9bbe4e9f088c673b8bf7e6201eeaecb9eb999b20471734192d7a12ef21#GoGoGrillazEatingBananasFtw?imageThumb=0C&time=0.00&sigTime=1328193128.4522 def _getSignature(self, query):23 if(query.startswith("?") == False):24 query = "?" + query25 passwdAndQuery = self._passwd + query26 return hashlib.sha224(passwdAndQuery).hexdigest()2728 def getUrlWithSignature(self, url):29 timeString = str(time.time() + self._offset)30 urlPlusTime = url + "&sigTime=" + timeString31 signature = self._getSignature(urlPlusTime)32 return urlPlusTime + "&sig=%s" % signature3334 def getSigantureFieldsForFile(self, fileType, fileName, fileData):35 returnFields = []36 timeString = str(time.time() + self._offset)37 returnFields.append(("sigTime", timeString))38 if(fileData == None):39 fileData = ""40 combinedString = self._passwd + "sigTime" + timeString + fileType + fileName + str(fileData)41 returnFields.append(("sig", hashlib.sha224(combinedString).hexdigest()))42 return returnFields4344 def verifySignature(self, url):45 urlSplit = url.split("&sig=", 1)46 query = urlSplit[0]47 querySignature = urlSplit[1]48 if(self._getSignature(query) == querySignature):49 urlSplit2 = query.split("&sigTime=", 1)50 query = urlSplit2[0]51 queryTime = float(urlSplit2[1])52 if(abs(time.time() - queryTime) < 30.0):53 return query54 else:55 print "abs(time.time() - queryTime) >= 30.0 " + str(abs(time.time() - queryTime)) + " time: " + str(time.time()) + " queryTime: " + str(queryTime)56 else:57 print "self._getSignature(query) != querySignature " + str(self._getSignature(query)) + " X " + str(querySignature)58 return None5960 def verifySignatureFields(self, fileType, fileName, fileData, sigTime, sig):61 combinedString = self._passwd + "sigTime" + str(sigTime) + fileType + fileName + str(fileData)62 calcSignature = hashlib.sha224(combinedString).hexdigest()63 if(calcSignature == sig):64 if(abs(time.time() - sigTime) < 30.0):65 return True66 return False67 68def getDefaultUrlSignaturePasswd():69 return "GoGoGrillazEatingBananasFtw"
...
Anagrams.py
Source: Anagrams.py
1# -*- coding: utf-8 -*-2"""3Created on Tue Aug 25 15:09:40 20204@author: santhilata5"""6'''7Given a string s and a non-empty string p, find all the start indices of p's anagrams in s.8Strings consists of lowercase English letters only and the length of both strings s and p will 9not be larger than 20,100.10The order of output does not matter.11Example 1:12 Input: s: "cbaebabacd" p: "abc"13 Output : [0,6]14 15Example 2:16 Input: s: "abab" p: "ab"17 Output: [0,1,2]18'''19s= "abab"20p= "ab"21#s= "cbaebabacd" 22#p= "abc"23def _getSignature(st):24 25 arr = [0]*2626 for ch in st:27 pos = ord(ch)-9728 arr[pos] += 129 30 signature = ''.join([str(i) for i in arr])31 return signature32def _findAnagrams(s, p):33 34 if len(s)<len(p):35 return [-1]36 37 if len(s) == len(p):38 if s==p:39 return [0]40 else:41 return [-1]42 43 window = len(p)44 result =[]45 sign_s = _getSignature(p)46 47 for i in range(len(s)-window+1):48 49 temp = _getSignature(s[i:i+window])50 51 if sign_s == temp:52 53 result.append(i)54 55 return result56result = _findAnagrams(s,p)57print(result)58from collections import Counter59def _findAnagrams1(s,p):60 61 result = []62 if len(s)<len(p):63 return result64 65 if len(s) == len(p):66 if s==p:67 return [0]68 else:69 return result70 71 72 window = len(p)73 74 sign_s = Counter(p)75 76 for i in range(len(s)-window+1):77 78 temp = Counter(s[i:i+window])79 80 if sign_s == temp:81 82 result.append(i)83 84 return result85result = _findAnagrams1(s, p)86print(result)87def findAnagrams_best( s: str, p: str) :88 answer = []89 m, n = len(s), len(p)90 if m < n:91 return answer92 pCounter = Counter(p)93 sCounter = Counter(s[:n-1])94 print(pCounter)95 print(sCounter)96 index = 097 for index in range(n - 1, m):98 sCounter[s[index]] += 199 if sCounter == pCounter:100 answer.append(index - n + 1)101 sCounter[s[index - n + 1]] -= 1102 if sCounter[s[index - n + 1]] == 0:103 del sCounter[s[index - n + 1]]104 return answer105result = findAnagrams_best(s, p)...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!